﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using System.Diagnostics;
using System.Net;

//sdk自定义类
using NS_OpenApiV3;
using NS_SnsNetWork;
using NS_SnsSigCheck;
using NS_SnsStat;
//Log自定义类
using Log4Net;
using System.Net.Sockets;

namespace PollServer
{
    public partial class Form1 : Form
    {
        //服务器数量
        public int servernum = 0;
        //处理线程数量
        public int threadnum = 0;

        /// <summary>
        /// 变量
        /// </summary>
        private bool windowCreate = true;

        private GameInfo[] DbInfoVec = new GameInfo[40];

        private string server_name = ""; //PAY 支付 
        private string pull_name = ""; //数据上报 域名或IP
        private int svrid = 0;

        private int appid = 1104341746;
        private string appkey = "q1HDxNVRo6WULl7d";

        /// <summary>
        /// 需要上报的平台
        /// </summary>
        public LogPlat[] logs;

        /// <summary>
        /// 需要上报的项目 
        /// (由于多个平台上报同一份数据，所以单数据复平台上报)
        /// </summary>
        public Dictionary<string, GameDbDelegate> allfunc;
        //SDK
        public OpenApiV3 sdk;
        //线程委托1 生产者 从数据库中获取数据
        public GameDbDelegate getdbdelegate;
        //线程委托1 消费者 从队列中取出数据并处理
        public GameDbDelegate dealdelegate;
        //测试用委托
        public GameDbDelegate testdelegate;
        //本机内网IP
        public long localip;
        //本机IP
        public string localIpStr;

        public Form1()
        {
            InitializeComponent();

            string configpath = Application.StartupPath + "\\config.ini";
            if (!File.Exists(configpath))
            {
                return;
            }
            //
            INI config = new INI(configpath);
            appid = Convert.ToInt32(config.ReadValue("APP", "APPID")); //获取平台APPID
            appkey = config.ReadValue("APP", "APPKEY");                //获取平台APPKEY
            servernum = Convert.ToInt32(config.ReadValue("Main", "SvrNum"));
            threadnum = Convert.ToInt32(config.ReadValue("Main", "ThreadNum"));
            localIpStr = Convert.ToString(config.ReadValue("Main", "LocalIp"));

            //需要上报数据的平台数量
            int platNum = Convert.ToInt32(config.ReadValue("Main", "Num"));
            logs = new LogPlat[platNum];
            allfunc = new Dictionary<string, GameDbDelegate>();
            //平台上报配置
            for (int i = 1; i <= platNum; i++)
            {
                string plats = "Plat" + i;
                LogPlat log = new LogPlat();
                log.WebServer = config.ReadValue(plats, "WebServer"); //上报数据地址
                log.platname = config.ReadValue(plats, "Name"); //获取需要上报的平台名称
                //初始化SDK
                log.sdk = new OpenApiV3(appid, appkey);
                log.sdk.SetServerName(log.WebServer);
                //需要上报数据项
                int funcnum = Convert.ToInt32(config.ReadValue(plats, "Fnum"));
                //log.func = new GameDbDelegate[funcnum];
                for (int t = 1; t <= funcnum; t++)
                {
                    string key = "func" + t;
                    string funcname = config.ReadValue(plats, key);
                    GameDbDelegate gdb = GetPlatLogFuncs(funcname);
                    if (!(log.func.ContainsKey(funcname) || gdb == null))
                    {
                        log.func.Add(funcname, GetFuncLogType(log.platname, funcname));
                    }
                    //
                    if (!(allfunc.ContainsKey(funcname) || gdb == null))
                    {
                        allfunc.Add(funcname, gdb);
                    }
                }

                logs[i - 1] = log;
            }
        }

        //根据平台名称获取平台
        public LogPlat GetPlatLog(string pname)
        {
            LogPlat ret = null;
            foreach (LogPlat log in logs)
            {
                if (log != null)
                {
                    if (string.Compare(log.platname, pname) == 0)
                    {
                        ret = log;
                        break;
                    }
                }
            }
            return ret;
        }

        protected override void OnActivated(EventArgs e)
        {
            if (windowCreate)
            {
                base.Visible = false;
                windowCreate = false;
            }

            base.OnActivated(e);
        }

        //超时 日志处理
        public static void timeout_console_node(object obj)
        {
            DataNode node = obj as DataNode;
            int _type = Convert.ToInt32(node._type);
            if (_type > 0)
            {
                string dtJson = TableHelper.ToJson(node._dt);
                string ret = "处理数据超时30秒, 类型：" + _type + "\r\n";
                ret += dtJson;
                LogHelper.WriteLog(ret);
            }
            else
            {
                string ret = "DB 取数据超时30秒：";
                if (node._delegate != null)
                {
                    ret += "Method： " + Convert.ToString(node._delegate.Method.Name);
                }

                GameDbInfo c_dbInfo = node._gmInfo.center_db;
                GameDbInfo l_dbInfo = node._gmInfo.log_db;
                if (c_dbInfo != null)
                {
                    ret += " CentrDb:   " + c_dbInfo.DBName + "   " + c_dbInfo.DBPort;
                }
                if (l_dbInfo != null)
                {
                    ret += " LogDb:   " + l_dbInfo.DBName + "   " + l_dbInfo.DBPort;
                }

                LogHelper.WriteLog(ret);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            /*初始化SDK
            sdk = new OpenApiV3(appid, appkey);
            sdk.SetServerName(server_name);
            */
            //
            //定义委托
            getdbdelegate = SyncGetDbInfo;
            dealdelegate = SyncDealNode;
            //testdelegate = SyncTestGame;
            //获取本机IP(作serverip使用)
            localip = GetLocalIp();

            if (servernum == 0) //当svrnum== 0 
            {
                //推送开平大区列表
                notic_open_server();

                //关闭程序
                Close();
            }
            else
            {
                //启动生产者
                MainThreadProc();
                //启动消费者 启动20个消费者
                ThreadMgr.CreateDealThread(dealdelegate, threadnum);
            }
        }

        //根据配置文件设置上报数据的处理函数
        public GameDbDelegate GetPlatLogFuncs(string pname)
        {
            GameDbDelegate gdelegate = null;
            if (string.Compare(pname, "charge") == 0)
            {
                //gdelegate = sync_charge_ret; //支付确认
            }
            else if (string.Compare(pname, "buy") == 0)
            {
                gdelegate = sync_buy_log; //支付购买道具
            }
            else if (string.Compare(pname, "quit") == 0)
            {
                gdelegate = sync_quit_log; //退出
            }
            else if (string.Compare(pname, "create") == 0)
            {
                gdelegate = sync_create_log; ////创建角色
            }
            else if (string.Compare(pname, "login") == 0)
            {
                gdelegate = sync_login_log; //登入
            }
            else if (string.Compare(pname, "online") == 0)
            {
                gdelegate = sync_online_log; //在线统计
            }
            else if (string.Compare(pname, "error") == 0)
            {
                //gdelegate = sync_recharge_log; //错误数据统计
                //屏蔽错误上报功能
                //gdelegate = sync_error_log; //web上报错误 这里重新上报
            }
            else if (string.Compare(pname, "recharge") == 0)
            {
                gdelegate = sync_rechareg_log; //开平充值上报
            }
            return gdelegate;
        }

        //取本机内网IP
        private long GetLocalIp()
        {
            string hostname = Dns.GetHostName();//得到本机名   
            IPHostEntry localhost = Dns.GetHostEntry(hostname);

            IPAddress localaddr = null;
            for (int i = 0; i < localhost.AddressList.Length; i++)
            {
                //从IP地址列表中筛选出IPv4类型的IP地址
                //AddressFamily.InterNetwork表示此IP为IPv4,
                //AddressFamily.InterNetworkV6表示此地址为IPv6类型
                if (localhost.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
                {
                    localaddr = localhost.AddressList[i];
                    break;
                }
            }

            if (localaddr == null)
                return 0;
            //取IP地址字符数组
            byte[] ips = localaddr.GetAddressBytes();
            //     对于 IPv4，返回 System.Net.Sockets.AddressFamily.InterNetwork；
            //  对于 IPv6，返回 System.Net.Sockets.AddressFamily.InterNetworkV6。
            if (localaddr.AddressFamily == AddressFamily.InterNetwork)
            {
                //转换为长整形数组
                return BitConverter.ToInt32(ips, 0);
            }
            else if (localaddr.AddressFamily == AddressFamily.InterNetworkV6)
            {
                return BitConverter.ToInt64(ips, 0);
            }
            return 0;
        }

        private bool CheckDbName(string dbname, string logname)
        {
            bool ret = false;
            foreach (GameInfo game in DbInfoVec)
            {
                if (game == null)
                {
                    continue;
                }
                if (game.center_db != null && game.log_db != null &&
                        game.center_db.DBName == dbname && game.log_db.DBName == logname)
                {
                    ret = true;
                    break;
                }
            }
            return ret;
        }

        private void notic_open_server()
        {
            try
            {
                GameDbInfo dbInfo = GetCenterDb();
                if (dbInfo == null)
                    throw new Exception("没有取到中控数据连接信息");
                //
                notic_open_server_Log(dbInfo);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("notic_open_server ", ex);
            }

        }

        //获取中心库DB信息
        private GameDbInfo GetCenterDb()
        {
            GameDbInfo log = null;
            string center_dbconfig = "D:\\server\\CenterServer\\dbcentercfg.ini";

            if (File.Exists(center_dbconfig))
            {
                INI logIniFile = new INI(center_dbconfig);

                log = new GameDbInfo();

                log.DBIP = logIniFile.ReadValue("DATABASE", "IP");
                log.DBName = logIniFile.ReadValue("DATABASE", "DEFAULTDB");
                log.Account = logIniFile.ReadValue("DATABASE", "ACCOUNT");
                log.PassWord = logIniFile.ReadValue("DATABASE", "PASSWORD");
                log.DBPort = logIniFile.ReadValue("DATABASE", "DBPORT");
                if (log.DBPort == "")
                {
                    log.DBPort = "3306";
                }
            }
            return log;
        }
        //推送开平大区列表
        private void notic_open_server_Log(GameDbInfo dbInfo)
        {
            using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
            {
                //推送
                DataTable dataTable = sqlCon.GetDataTable("select UNIX_TIMESTAMP(now()) ieventtime, qqserverid worldid, servername, UNIX_TIMESTAMP(opentime) opentime from t_product_server");
                int rows = dataTable.Rows.Count;
                if (rows > 0)
                {
                    String logstr = "";
                    LogPlat open = GetPlatLog("Open");
                    for (int n = 0; n < rows; n++)
                    {
                        DataRow dr = dataTable.Rows[n];
                        string iappid = Convert.ToString(open.sdk.APPID);
                        string idomain = "0";
                        string ioptype = "4";
                        string iactionid = "0";
                        string ieventtime = Convert.ToString(dr["ieventtime"].ToString());
                        string iworldid = Convert.ToString(dr["worldid"].ToString());
                        string vparam_1 = Convert.ToString(dr["servername"].ToString());
                        string iparam_2 = "0";
                        string vparam_2 = "";
                        string vparam_3 = Convert.ToString(dr["opentime"].ToString());

                        Dictionary<string, string> param = new Dictionary<string, string>();
                        param.Add("iappid", iappid);
                        param.Add("idomain", idomain);
                        param.Add("ioptype", ioptype);
                        param.Add("iactionid", iactionid);
                        param.Add("ieventtime", ieventtime);
                        param.Add("iworldid", iworldid);
                        param.Add("vparam_1", vparam_1);
                        param.Add("iparam_2", iparam_2);
                        param.Add("vparam_2", vparam_2);
                        param.Add("vparam_3", vparam_3);

                        string query_string = SnsNetWork.MakeQueryString(param);
                        string script_name = "/report.php";
                        //执行API 上报数据
                        RstArray rs = open.sdk.ApiNoSig(script_name, param, false);
                        if (rs.Ret != 0) //执行失败
                        {
                            logstr += "上报大区列表失败： ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " SvrName: " + vparam_1 + "\n";
                        }
                    }
                    if (logstr.Length > 5)
                    {
                        LogHelper.WriteLog(logstr);
                    }
                    else
                    {
                        LogHelper.WriteLog("推送" + rows.ToString() + "条数据成功");
                    }
                }
            }
        }

        //针对具体某个ZoneServer生成单独的处理线程
        private void Begin_Thread_Game(int dirnum)
        {
            //
            string pay_config = "\\DBServer\\databaseserver.ini";
            string log_config = "\\LogServer\\dbcentercfg.ini";
            string dir = "D:\\Server";

            //
            string pay_dbconfig = "";
            string log_dbconfig = "";
            if (dirnum == 0)
            {
                pay_dbconfig = dir + pay_config;
                log_dbconfig = dir + log_config;
            }
            else
            {
                pay_dbconfig = dir + dirnum + pay_config;
                log_dbconfig = dir + dirnum + log_config;
            }

            if (File.Exists(pay_dbconfig) && File.Exists(log_dbconfig))
            {
                if (DbInfoVec[dirnum] == null)
                {
                    INI payIniFile = new INI(pay_dbconfig);
                    INI logIniFile = new INI(log_dbconfig);

                    string dbname = payIniFile.ReadValue("DATABASE", "DEFAULTDB");
                    string logname = logIniFile.ReadValue("DATABASE", "DEFAULTDB");

                    //相同配置不处理
                    if (CheckDbName(dbname, logname))
                    {
                        return;
                    }

                    DbInfoVec[dirnum] = new GameInfo();
                    //支付数据上报DB信息
                    DbInfoVec[dirnum].center_db.DBIP = payIniFile.ReadValue("DATABASE", "IP");
                    DbInfoVec[dirnum].center_db.DBName = payIniFile.ReadValue("DATABASE", "DEFAULTDB");
                    DbInfoVec[dirnum].center_db.Account = payIniFile.ReadValue("DATABASE", "ACCOUNT");
                    DbInfoVec[dirnum].center_db.PassWord = payIniFile.ReadValue("DATABASE", "PASSWORD");
                    DbInfoVec[dirnum].center_db.DBPort = payIniFile.ReadValue("DATABASE", "DBPORT");
                    if (DbInfoVec[dirnum].center_db.DBPort == "")
                    {
                        DbInfoVec[dirnum].center_db.DBPort = "3306";
                    }

                    //数据上报DB信息
                    DbInfoVec[dirnum].log_db.DBIP = logIniFile.ReadValue("DATABASE", "IP");
                    DbInfoVec[dirnum].log_db.DBName = logIniFile.ReadValue("DATABASE", "DEFAULTDB");
                    DbInfoVec[dirnum].log_db.Account = logIniFile.ReadValue("DATABASE", "ACCOUNT");
                    DbInfoVec[dirnum].log_db.PassWord = logIniFile.ReadValue("DATABASE", "PASSWORD");
                    DbInfoVec[dirnum].log_db.DBPort = logIniFile.ReadValue("DATABASE", "DBPORT");
                    if (DbInfoVec[dirnum].log_db.DBPort == "")
                    {
                        DbInfoVec[dirnum].log_db.DBPort = "3306";
                    }
                    //创建取数据处理线程
                    ThreadMgr.CreateDbThread(getdbdelegate, DbInfoVec[dirnum], 60000);

                    //创建测试线程
                    //ThreadMgr.CreateDbThread(testdelegate, DbInfoVec[i], 500);
                }
            }
        }

        // 主要线程处理
        private void MainThreadProc()
        {
            string acc_config = "D:\\Server\\AccountServer\\AccountCfg.ini";
            if (!File.Exists(acc_config))
            {
                LogHelper.WriteLog(acc_config + "配置文件不存在！");
                //关闭程序
                Close();
            }
            INI accIniFile = new INI(acc_config);
            string dbip = accIniFile.ReadValue("DATABASE", "IP");
            string dbname = accIniFile.ReadValue("DATABASE", "DEFAULTDB");
            string dbport = accIniFile.ReadValue("DATABASE", "DBPORT");
            string account = accIniFile.ReadValue("DATABASE", "ACCOUNT");
            string passwd = accIniFile.ReadValue("DATABASE", "PASSWORD");
            // 
            using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbip, account, passwd, dbname, dbport))
            {
                string sql = "select serverdir from  t_product_server where serverip='" + localIpStr + "' and status =1";
                LogHelper.WriteLog("SQL: " + sql);
                DataTable dt = sqlCon.GetDataTable(sql);
                int row = dt.Rows.Count;
                for (int n = 0; n < row; n++)
                {
                    DataRow dr = dt.Rows[n];
                    string serverdir = Convert.ToString(dr["serverdir"].ToString());
                    int dirnum = Convert.ToInt32(serverdir); //目录索引
                    Begin_Thread_Game(dirnum);
                }
            }
        }

        //处理DB线程委托
        public bool SyncGetDbInfo(object obj)
        {
            if (obj == null) return true;

            GameInfo dbInfo = obj as GameInfo;

            LockFreeQueue queue = LockFreeQueue.Queue;

            foreach (var item in allfunc)
            {
                GameDbDelegate _delegate = item.Value;
                if (_delegate != null)
                {
                    DataNode node = new DataNode(_delegate, dbInfo);
                    node.funcname = item.Key;
                    //把取数据做成节点 放入队列
                    queue.push(node);
                }
            }
            return true;
        }

        //处理数据上报
        public bool SyncDealNode(object obj)
        {
            if (obj == null) return true;

            DataNode node = obj as DataNode;
            switch (Convert.ToInt32(node._type))
            {
                case 0:
                    //数据节点
                    if (node._delegate != null)
                        node._delegate(node);
                    break;
                case 1:
                    //支付确认
                    notic_charege_ret(node._dbInfo, node._dt, node._sdk);
                    break;
                case 31: //创建角色 开平
                    notic_open_create_log(node._dbInfo, node._dt, node._sdk);
                    break;
                case 32: ////角色登入
                    notic_open_login_log(node._dbInfo, node._dt, node._sdk);
                    break;
                case 33: //角色登出
                    notic_open_quit_log(node._dbInfo, node._dt, node._sdk);
                    break;
                case 34: //角色消费或购买
                    notic_open_buy_log(node._dbInfo, node._dt, node._sdk);
                    break;
                case 35: //开平在线统计
                    notic_open_online_log(node._dbInfo, node._dt, node._sdk);
                    break;
                case 36: //开平充值
                    notic_open_recharge_log(node._dbInfo, node._dt, node._sdk);
                    break;
                case 70://QQ大厅退出
                    notic_qqgame_quit_log(node._dbInfo, node._dt, node._sdk);
                    break;
                case 50://消费日志推送 罗盘
                    notic_luopan_buy_log(node._dbInfo, node._dt, node._sdk);
                    break;
                case 51://玩家退出日志推送 罗盘
                    notic_luopan_quit_log(node._dbInfo, node._dt, node._sdk);
                    break;
                case 52: //罗盘货币消费
                    notic_luopan_online_log(node._dbInfo, node._dt, node._sdk);
                    break;
            }
            //             int thread = Thread.CurrentThread.ManagedThreadId;
            //             Console.WriteLine("处理线程：  " + thread);
            return true;
        }

        //判断该平台是否上报改项目
        public bool IsHasLogFunc(LogPlat plat, string funcname)
        {
            return plat.func.ContainsKey(funcname);
        }

        //根据平台名字和上报名字 获取上报类型
        public UPLOGTYPE GetFuncLogType(string platname, string funcname)
        {
            //是否是开平平台
            if (string.Compare(platname, "Open") == 0)
            {
                if (string.Compare(funcname, "quit") == 0)
                {
                    return UPLOGTYPE.OPEN_QUIT_LOG_TYPE;
                }
                else if (string.Compare(funcname, "buy") == 0)
                {
                    return UPLOGTYPE.OPEN_BUY_LOG_TYPE;
                }
                else if (string.Compare(funcname, "online") == 0)
                {
                    return UPLOGTYPE.OPEN_ONLINE_LOG_TYPE;
                }
            }
            else if (string.Compare(platname, "Luopan") == 0)
            {
                if (string.Compare(funcname, "quit") == 0)
                {
                    return UPLOGTYPE.LPAN_QUIT_LOG_TYPE;
                }
                else if (string.Compare(funcname, "buy") == 0)
                {
                    return UPLOGTYPE.LPAN_BUY_LOG_TYPE;
                }
                else if (string.Compare(funcname, "online") == 0)
                {
                    return UPLOGTYPE.LPAN_ONLINE_LOG_TYPE;
                }
            }
            return 0;
        }

        #region 取数据操作
        //支付确认 
        public bool sync_charge_ret(object obj)
        {
            DataNode pnode = obj as DataNode;

            GameDbInfo dbInfo = pnode._gmInfo.center_db;
            using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
            {
                //支付推送
                DataTable dataTable = sqlCon.GetDataTable("select ts,payitem,token,billno,apiversion,zoneid,providetype,provide_errno,provide_errmsg,amt,payamt_coins,pubacct_payamt_coins,account, openkey,pf from pay_token where roleid > 0 and confirm = 0 order by createtime asc limit 100");
                int row = dataTable.Rows.Count;
                if (row > 0)
                {
                    LockFreeQueue queue = LockFreeQueue.Queue;
                    foreach (LogPlat plat in logs)
                    {
                        if (IsHasLogFunc(plat, pnode.funcname))
                        {
                            UPLOGTYPE tmpType = GetFuncLogType(plat.platname, pnode.funcname);
                            //构造处理节点
                            DataNode node = new DataNode(tmpType, dbInfo, dataTable, plat.sdk);
                            queue.push(node);
                        }
                    }

                    //默认交易完成(防止支付记录被重复取)
                    for (int n = 0; n < row; n++)
                    {
                        DataRow dr = dataTable.Rows[n];
                        string token_id = Convert.ToString(dr["token"].ToString());
                        sqlCon.NonQueryExec("update pay_token set confirm = 1, confirmret = 0 where token = '" + token_id.ToString() + "'");
                    }
                }
            }
            return true;
        }

        //充值数据上报 
        public bool sync_rechareg_log(object obj)
        {
            DataNode pnode = obj as DataNode;

            GameDbInfo dbInfo = pnode._gmInfo.center_db;
            using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
            {
                //支付推送
                DataTable dataTable = sqlCon.GetDataTable("select token vparam_1,SUBSTRING(account,locate(char(31),account)+1)  openid,token vparam_2,amt/10+payamt_coins+pubacct_payamt_coins iparam_1,itemprice*itemnum iparam_2,platform idomain,zoneid iworldid,UNIX_TIMESTAMP(createtime) ieventTime,wdpid from pay_token where confirm=1 and syncret=0 and pf<>'pengwan' order by createtime asc limit 100");
                int row = dataTable.Rows.Count;
                if (row > 0)
                {
                    //默认交易完成(防止支付记录被重复取)
                    for (int n = 0; n < row; n++)
                    {
                        DataRow dr = dataTable.Rows[n];
                        string token_id = Convert.ToString(dr["vparam_1"].ToString());
                        sqlCon.NonQueryExec("update pay_token set syncret = 1 where token = '" + token_id.ToString() + "'");
                    }

                    LockFreeQueue queue = LockFreeQueue.Queue;
                    foreach (LogPlat plat in logs)
                    {
                        if (IsHasLogFunc(plat, pnode.funcname))
                        {
                            UPLOGTYPE tmpType = GetFuncLogType(plat.platname, pnode.funcname);
                            //构造处理节点
                            DataNode node = new DataNode(tmpType, dbInfo, dataTable, plat.sdk);
                            queue.push(node);
                        }
                    }
                }
            }
            return true;
        }

        //消费日志数据上报 
        public bool sync_buy_log(object obj)
        {
            DataNode pnode = obj as DataNode;

            GameDbInfo dbInfo = pnode._gmInfo.center_db;
            using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
            {
                DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
                Double nowtime = (DateTime.Now - startTime).TotalSeconds - 60 * 30; //提前60秒  
                string sql = "select id,b.serverid,u.qqserverid worldid,SUBSTRING(b.account,locate(char(31),b.account)+1) opopenid,u.playerip userip,u.platform domain,UNIX_TIMESTAMP(b.buytime) buytime,roleid opuid,itemid,itemnum itemcnt,point modifyfee,curcoins totalfee,rolelevel level, b.Info, b.wdpid from ( select * from log_buy where buytime >from_unixtime(" + nowtime + ")) b inner join t_u_login u on b.account=u.account and left(rolename,7)=u.serverid where b.isreport=0 order by buytime asc limit 100";
                //消费日志上报
                DataTable paydt = sqlCon.GetDataTable(sql);
                //("select id,b.serverid,u.qqserverid worldid,SUBSTRING(b.account,locate(char(31),b.account)+1) opopenid,u.playerip userip,u.platform domain,UNIX_TIMESTAMP(b.buytime) buytime,roleid opuid,itemid,itemnum itemcnt,point modifyfee,curcoins totalfee,rolelevel level, b.Info, b.wdpid from log_buy b inner join t_u_login u on b.account=u.account and left(rolename,7)=u.serverid where b.isreport=0 order by buytime asc limit 100");
                //构造处理节点
                int rows = paydt.Rows.Count;
                if (rows > 0)
                {
                    //默认交易完成(防止支付记录被重复取)
                    for (int n = 0; n < rows; n++)
                    {
                        DataRow dr = paydt.Rows[n];
                        string id = Convert.ToString(dr["id"].ToString());
                        //string id = Convert.ToString(paydt.Rows[n][0]);
                        sqlCon.NonQueryExec("update log_buy set isreport = 1 where id = '" + id.ToString() + "'");
                    }

                    LockFreeQueue queue = LockFreeQueue.Queue;
                    foreach (LogPlat plat in logs)
                    {
                        if (IsHasLogFunc(plat, pnode.funcname))
                        {
                            UPLOGTYPE tmpType = GetFuncLogType(plat.platname, pnode.funcname);
                            //构造处理节点
                            DataNode node = new DataNode(tmpType, pnode._gmInfo.log_db, paydt, plat.sdk);
                            queue.push(node);
                        }
                    }
                }
            }
            return true;
        }

        public DataTable ToDataTable(DataRow[] rows)
        {
            if (rows == null || rows.Length == 0) return null;
            DataTable tmp = rows[0].Table.Clone();  // 复制DataRow的表结构  
            foreach (DataRow row in rows)
                tmp.Rows.Add(row.ItemArray);  // 将DataRow添加到DataTable中  
            return tmp;
        }

        //玩家退出数据上报 
        public bool sync_quit_log(object obj)
        {
            DataNode pnode = obj as DataNode;

            GameDbInfo dbInfo = pnode._gmInfo.log_db;
            using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
            {
                //退出数据上报
                //DataTable quitdt = sqlCon.GetDataTable("select id,serverid,substring_index(account,char(31),-1) opopenid,playerip userip,UNIX_TIMESTAMP(logouttime) logouttime, onlinetime,platform domain,roleid opuid, school, rolelevel level,wdpid,qqserverid worldid,curbindpoints,curgiftcoins, point, pf from log_logout where isreport=0 order by logouttime asc limit 100");
                //select id,serverid,SUBSTRING(account,locate(char(31),account)+1) opopenid,playerip userip,UNIX_TIMESTAMP(logouttime) logouttime, UNIX_TIMESTAMP(onlinetime) onlinetime,platform domain,roleid opuid, school, rolelevel level,wdpid,qqserverid worldid,curbindpoints,curgiftcoins, point from log_logout where isreport=0 order by logouttime asc limit 100")
                //select id,serverid,substring_index(account,char(31),-1) opopenid,playerip userip,UNIX_TIMESTAMP(logouttime) logouttime, onlinetime,roleid from log_logout where pf='qqgame'
                DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
                Double nowtime = (DateTime.Now - startTime).TotalSeconds - (3600 * 12); //提前1小时  
                string sql = "select l.id,l.serverid,substring_index(l.account,char(31),-1) opopenid,l.playerip userip,UNIX_TIMESTAMP(logouttime) logouttime, onlinetime,l.platform domain,l.roleid opuid, l.school, l.rolelevel level,l.wdpid,l.qqserverid worldid,curbindpoints,curgiftcoins,point,l.pf,p.openkey from " + dbInfo.DBName + ".log_logout l inner join " + pnode._gmInfo.center_db.DBName + ".t_u_login p on l.account=p.account and l.serverid=p.serverid where l.IsReport=0 and  logouttime>from_unixtime(" + nowtime + ")  order by logouttime asc limit 100";

                DataTable quitdt = sqlCon.GetDataTable(sql);
                int row = quitdt.Rows.Count;
                if (row > 0)
                {
                    for (int n = 0; n < row; n++)
                    {
                        DataRow dr = quitdt.Rows[n];
                        string id = Convert.ToString(dr["id"].ToString());
                        //string id = Convert.ToString(quitdt.Rows[n][0]);
                        sqlCon.NonQueryExec("update log_logout set isreport = 1 where id = '" + id.ToString() + "'");
                    }

                    LockFreeQueue queue = LockFreeQueue.Queue;
                    foreach (LogPlat plat in logs)
                    {
                        if (IsHasLogFunc(plat, pnode.funcname))
                        {
                            UPLOGTYPE tmpType = GetFuncLogType(plat.platname, pnode.funcname);
                            //构造处理节点
                            DataNode node = new DataNode(tmpType, dbInfo, quitdt, plat.sdk);
                            queue.push(node);
                        }
                    }
                }
            }
            return true;
        }
        //创建角色 
        public bool sync_create_log(object obj)
        {
            DataNode pnode = obj as DataNode;

            GameDbInfo dbInfo = pnode._gmInfo.center_db;
            using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
            {
                DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
                Double nowtime = (DateTime.Now - startTime).TotalSeconds - 60 * 30; //提前60秒  
                string sql = "select id, lr.account, platform domain,qqserverid worldid, SUBSTRING(lr.account,locate(char(31),lr.account)+1) openid,ip userip,UNIX_TIMESTAMP(logintime) logintime,logintime, tc.roleid, tc.school, ifnull(tp.playerlevel,1) level,lr.curpoints,lr.curbindpoints,lr.curgiftcoins,lr.wdpid,UNIX_TIMESTAMP(tc.recordtime) createtime, ifnull(via,'') via,lr.allonlinetime from  (select id,account,Ip,logintime,IsReport, curpoints,curbindpoints,curgiftcoins,wdpid,allonlinetime,PlatForm,QQServerId,Via,serverid from log_reglogin where logintime>=from_unixtime(" + nowtime + ")) lr inner join t_u_createrole tc on lr.account = tc.account and lr.serverid=tc.serverid left join t_u_playerinfo tp on tp.account = lr.account where lr.isreport=0 order by logintime asc limit 100";
                //创建角色日志数据上报
                DataTable dt = sqlCon.GetDataTable(sql);
                //("select tc.account, tl.platform domain, tl.qqserverid worldid, tc.serverid,SUBSTRING(tc.account,locate(char(31),tc.account)+1) opopenid,tc.playerip userip,UNIX_TIMESTAMP(tc.recordtime) ieventtime,tc.roleid, tc.school,tc.wdpid, tl.via from t_u_createrole tc inner join t_u_login tl on tl.account = tc.account where tc.isreport=0 order by ieventtime asc limit 100");
                int row = dt.Rows.Count;
                if (row > 0)
                {
                    //默认交易完成(防止支付记录被重复取)
                    for (int n = 0; n < row; n++)
                    {
                        DataRow dr = dt.Rows[n];
                        string account = Convert.ToString(dr["account"].ToString());
                        sqlCon.NonQueryExec("update t_u_createrole set isreport = 1 where account = '" + account.ToString() + "'");
                    }

                    LockFreeQueue queue = LockFreeQueue.Queue;
                    foreach (LogPlat plat in logs)
                    {
                        if (IsHasLogFunc(plat, pnode.funcname))
                        {
                            UPLOGTYPE tmpType = GetFuncLogType(plat.platname, pnode.funcname);
                            //构造处理节点
                            DataNode node = new DataNode(tmpType, dbInfo, dt, plat.sdk);
                            queue.push(node);
                        }
                    }
                }
            }
            return true;
        }
        //玩家登入
        public bool sync_login_log(object obj)
        {
            //
            DataNode pnode = obj as DataNode;

            GameDbInfo dbInfo = pnode._gmInfo.center_db;
            using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
            {
                DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
                Double nowtime = (DateTime.Now - startTime).TotalSeconds - 60 * 30; //提前60秒  
                string sql = "select id,platform domain,qqserverid worldid, SUBSTRING(lr.account,locate(char(31),lr.account)+1) openid,ip userip,UNIX_TIMESTAMP(logintime) logintime,logintime, tc.roleid, tc.school, ifnull(tp.playerlevel,1) level,lr.curpoints,lr.curbindpoints,lr.curgiftcoins,lr.wdpid,UNIX_TIMESTAMP(tc.recordtime) createtime, ifnull(via,'') via,lr.allonlinetime from  (select id,account,Ip,logintime,IsReport, curpoints,curbindpoints,curgiftcoins,wdpid,allonlinetime,PlatForm,QQServerId,Via from log_reglogin where logintime>from_unixtime(" + nowtime + ")) lr left join t_u_createrole tc on lr.account = tc.account left join t_u_playerinfo tp on tp.account = lr.account where lr.isreport=0 order by logintime asc limit 100";
                DataTable dt = sqlCon.GetDataTable(sql);
                //"select id,platform domain,qqserverid worldid, SUBSTRING(lr.account,locate(char(31),lr.account)+1) openid,ip userip, UNIX_TIMESTAMP(logintime) logintime,logintime, tc.roleid, tc.school, ifnull(tp.playerlevel,1) level,lr.curpoints,lr.curbindpoints,lr.curgiftcoins,lr.wdpid,UNIX_TIMESTAMP(tc.recordtime) createtime, ifnull(via,'') via,lr.allonlinetime from log_reglogin lr left join t_u_createrole tc on lr.account = tc.account left join t_u_playerinfo tp on tp.account = lr.account where lr.isreport=0 order by logintime asc limit 100");
                int row = dt.Rows.Count;
                if (row > 0)
                {
                    for (int n = 0; n < row; n++)
                    {
                        DataRow dr = dt.Rows[n];
                        string id = Convert.ToString(dr["id"].ToString());
                        //string id = Convert.ToString(dt.Rows[n][0]);
                        sqlCon.NonQueryExec("update log_reglogin set isreport = 1 where id = '" + id.ToString() + "'");
                    }

                    LockFreeQueue queue = LockFreeQueue.Queue;
                    foreach (LogPlat plat in logs)
                    {
                        if (IsHasLogFunc(plat, pnode.funcname))
                        {
                            UPLOGTYPE tmpType = GetFuncLogType(plat.platname, pnode.funcname);
                            //构造处理节点
                            DataNode node = new DataNode(tmpType, dbInfo, dt, plat.sdk);
                            queue.push(node);
                        }
                    }

                    //strlog += "获取并处理了" + row.ToString() + "条记录\r\n";
                }
            }
            //LogHelper.write(strlog);
            return true;
        }
        //在线统计  
        public bool sync_online_log(object obj)
        {
            DataNode pnode = obj as DataNode;

            GameDbInfo dbInfo = pnode._gmInfo.log_db;
            using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
            {
                //退出数据上报
                DataTable dt = sqlCon.GetDataTable("select id,qqserverid worldid, UNIX_TIMESTAMP(CurTime) ieventTime, serverid, onlinenum from log_online where isreport=0");
                int row = dt.Rows.Count;
                if (row > 0)
                {
                    //默认交易完成(防止支付记录被重复取)
                    for (int n = 0; n < row; n++)
                    {
                        DataRow dr = dt.Rows[n];
                        string id = Convert.ToString(dr["id"].ToString());
                        //string id = Convert.ToString(dt.Rows[n][0]);
                        sqlCon.NonQueryExec("update log_online set isreport = 1 where id = '" + id.ToString() + "'");
                    }

                    LockFreeQueue queue = LockFreeQueue.Queue;
                    foreach (LogPlat plat in logs)
                    {
                        if (IsHasLogFunc(plat, pnode.funcname))
                        {
                            UPLOGTYPE tmpType = GetFuncLogType(plat.platname, pnode.funcname);
                            //构造处理节点
                            DataNode node = new DataNode(tmpType, dbInfo, dt, plat.sdk);
                            queue.push(node);
                        }
                    }
                }
            }
            return true;
        }
        /*
        //玩家注册日志 
        public bool sync_register_log(object obj)
        {
            DataNode pnode = obj as DataNode;

            GameDbInfo dbInfo = pnode._gmInfo.center_db;
            using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
            {
                //退出数据上报
                DataTable dt = sqlCon.GetDataTable("select tl.account,playerip,UNIX_TIMESTAMP(createtime) createtime,tl.serverid,tp.roleid,SUBSTRING(tl.account,locate(char(31),tl.account)) openid, pf,openkey,pfkey,x5sig,wdpid from t_u_login tl inner join t_u_playerinfo tp on tp.account = tl.account where isreport=0 order by createtime asc limit 100");
                    
                int row = dt.Rows.Count;
                if (row > 0)
                {
                    LogPlat union = GetPlatLog("Union");
                    //构造处理节点
                    DataNode node = new DataNode(UPLOGTYPE.UNION_REGISTER_LOG_TYPE, dbInfo, dt, union.sdk);

                    LockFreeQueue queue = LockFreeQueue.Queue;
                    if (queue.push(node))
                    {
                        //默认交易完成(防止支付记录被重复取)
                        for (int n = 0; n < row; n++)
                        {
                            string account = Convert.ToString(dt.Rows[n][0]);
                            sqlCon.NonQueryExec("update t_u_login set isreport = 1 where account = '" + account.ToString() + "'");
                        }
                    } 
                }            
            }
            return true;
        }

        //注废弃
        //该服上报数据 上报失败重复上报 (开平 + 罗盘 + 联盟)
        public bool sync_error_log(object obj)
        {
            return false;

            DataNode pnode = obj as DataNode;

            GameDbInfo dbInfo = pnode._gmInfo.log_db;
            using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
            {
                //数据重复上报
                //select id, type, eventid, version, appid, userip, svrip, time, domain, worldid, opuid, opopenid,touid, toopenid, level, openkey, pfkey, pf, x5sig,wdpid, itemid, itemcnt, iteminfo, fee, coin, ticket,serial from log_report where isreport=0 order by time asc limit 100
                DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
                Double nowtime = (DateTime.Now - startTime).TotalSeconds - (3600 * 12); //只上报12小时内的错误日志
                DataTable dt = sqlCon.GetDataTable("select * from log_report where isreport=0 and time >from_unixtime(" + nowtime + ") order by time asc limit 100");
                int rows = dt.Rows.Count;
                if (rows > 0)
                {
                    LockFreeQueue queue = LockFreeQueue.Queue;
                    LogPlat txlog = GetPlatLog("Tx");
                    LogPlat unlog = GetPlatLog("Union");
                    LogPlat oplog = GetPlatLog("Open");

                    //默认所有数据都上报成功
                    for (int i = 0; i < rows; i++)
                    {
                        DataRow dr = dt.Rows[i];
                        string id = Convert.ToString(dr["id"].ToString());
                        //string id = Convert.ToString(dt.Rows[i][0]);
                        sqlCon.NonQueryExec("update log_report set isreport = 1 where id = '" + id.ToString() + "'");
                    }
                    //分发所有数据到具体处理
                    //1.罗盘注册,2.罗盘登录,3.罗盘接受邀请注册,4.罗盘邀请他人注册,5.罗盘支付充值,
                    //6.联盟注册,7.联盟登录,8.联盟支付充值,9.罗盘消费日志, 10.开平消费日志
                    //11.罗盘登出日志 12.开平登出日志
                    for (int n = 1; n <= 12; n++)
                    {
                        DataRow[] eRow = dt.Select("type =" + Convert.ToString(n));
                        if (eRow.Length > 0)
                        {
                            //构造数据
                            DataTable dtRet = new DataTable();
                            dtRet = dt.Clone();

                            for (int i = 0; i < eRow.Length; i++)
                            {
                                dtRet.ImportRow((DataRow)eRow[i]);
                            }
                            switch (n)
                            {
                                case 1: //罗盘注册
                                    //构造处理节点
                                    DataNode node1 = new DataNode(UPLOGTYPE.SYNC_REGISTER_RELOG_TYPE, dbInfo, dtRet, txlog.sdk);
                                    queue.push(node1);
                                    break;
                                case 2: //罗盘登录
                                    DataNode node2 = new DataNode(UPLOGTYPE.SYNC_LOGIN_RELOG_TYPE, dbInfo, dtRet, txlog.sdk);
                                    queue.push(node2);
                                    break;
                                case 3: //罗盘接受邀请注册
                                    DataNode node3 = new DataNode(UPLOGTYPE.SYNC_ACCEPT_RELOG_TYPE, dbInfo, dtRet, txlog.sdk);
                                    queue.push(node3);
                                    break;
                                case 4: //罗盘邀请他人注册
                                    DataNode node4 = new DataNode(UPLOGTYPE.SYNC_INVITE_RELOG_TYPE, dbInfo, dtRet, txlog.sdk);
                                    queue.push(node4);
                                    break;
                                case 5: //罗盘支付充值 
                                    DataNode node5 = new DataNode(UPLOGTYPE.SYNC_PAYCHARGE_RELOG_TYPE, dbInfo, dtRet, txlog.sdk);
                                    queue.push(node5);
                                    break;
                                case 6: //联盟注册
                                    DataNode node6 = new DataNode(UPLOGTYPE.UNION_REGISTER_RELOG_TYPE, dbInfo, dtRet, unlog.sdk);
                                    queue.push(node6);
                                    break;
                                case 7: //联盟登录
                                    DataNode node7 = new DataNode(UPLOGTYPE.UNION_LOGIN_RELOG_TYPE, dbInfo, dtRet, unlog.sdk);
                                    queue.push(node7);
                                    break;
                                case 8: //联盟支付充值
                                    DataNode node8 = new DataNode(UPLOGTYPE.UNION_PAYCHARGE_RELOG_TYPE, dbInfo, dtRet, unlog.sdk);
                                    queue.push(node8);
                                    break;
                                case 9: //罗盘消费日志
                                    DataNode node9 = new DataNode(UPLOGTYPE.SYNC_BUY_RELOG_TYPE, dbInfo, dtRet, txlog.sdk);
                                    queue.push(node9);
                                    break;
                                case 10: //开平消费日志
                                    DataNode node10 = new DataNode(UPLOGTYPE.OPEN_BUY_RELOG_TYPE, dbInfo, dtRet, oplog.sdk);
                                    queue.push(node10);
                                    break;
                                case 11: //罗盘登出日志
                                    DataNode node11 = new DataNode(UPLOGTYPE.SYNC_QUIT_RELOG_TYPE, dbInfo, dtRet, txlog.sdk);
                                    queue.push(node11);
                                    break;
                                case 12: //开平登出日志
                                    DataNode node12 = new DataNode(UPLOGTYPE.OPEN_QUIT_RELOG_TYPE, dbInfo, dtRet, oplog.sdk);
                                    queue.push(node12);
                                    break;
                            }
                        }
                    }
                }
            }
            return true;
        }
         */
        #endregion

        #region 上报数据操作
        //支付确认
        public void notic_charege_ret(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            string logstr = "";
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                string ts = Convert.ToString(dataTable.Rows[n][0]);
                string payitem = Convert.ToString(dataTable.Rows[n][1]);        // 商品ID * 商品单价 * 商品数量
                string token_id = Convert.ToString(dataTable.Rows[n][2]);
                string billno = Convert.ToString(dataTable.Rows[n][3]);
                string version = Convert.ToString(dataTable.Rows[n][4]);
                string zoneid = Convert.ToString(dataTable.Rows[n][5]);
                string providetype = Convert.ToString(dataTable.Rows[n][6]);
                string provide_errno = Convert.ToString(dataTable.Rows[n][7]);
                string provide_errmsg = Convert.ToString(dataTable.Rows[n][8]);
                string amt = Convert.ToString(dataTable.Rows[n][9]);
                string payamt_coins = Convert.ToString(dataTable.Rows[n][10]);
                string pubacct_payamt_coins = Convert.ToString(dataTable.Rows[n][11]);
                // 公共参数
                string openid = Convert.ToString(dataTable.Rows[n][12]);
                string openkey = Convert.ToString(dataTable.Rows[n][13]);
                string pf = Convert.ToString(dataTable.Rows[n][14]);

                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("ts", ts);
                param.Add("payitem", payitem);
                param.Add("token_id", token_id);
                param.Add("billno", billno);
                param.Add("version", version);
                param.Add("zoneid", zoneid);
                param.Add("providetype", providetype);
                param.Add("provide_errno", provide_errno);
                param.Add("provide_errmsg", provide_errmsg);
                param.Add("amt", amt);
                param.Add("payamt_coins", payamt_coins);
                param.Add("pubacct_payamt_coins", pubacct_payamt_coins);

                // 加入公共参数
                param.Add("openid", openid.ToUpper());
                param.Add("openkey", openkey);
                param.Add("pf", pf);
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/v3/pay/confirm_delivery";
                //执行API 通知QQ支付服务器 
                RstArray rs = sdk.Api(script_name, param);
                /*
                ret = 0: 正确返回
                ret > 0: 调用OpenAPI时发生错误，需要开发者进行相应的处理。
                -50 <= ret <= -1: 接口调用不能通过接口代理机校验，需要开发者进行相应的处理。
                ret <-50: 系统内部错误，请通过企业QQ联系技术支持，调查问题原因并获得解决方案
                //
                1069     交易已成功结束，通知过晚（已扣款）。操作指引：交易成功，无需后续操作。 
                */
                if (rs.Ret == 0 || rs.Ret == 1069)
                {
                    logstr += "成功 token = '" + token_id.ToString() + "' \r\n";
                }
                else
                {
                    //发生错误
                    logstr += "失败 token = '" + token_id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " \r\n";
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        sqlCon.NonQueryExec("update pay_token set confirm = 0, confirmret = " + rs.Ret + " where token = '" + token_id.ToString() + "'");
                    }
                }
            }

            if (rows > 0)
            {
                LogHelper.WriteLog(logstr);
            }
        }

        //充值上报 (开平)
        public void notic_open_recharge_log(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            string logstr = "";
            string errstr = "";
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                //
                string vparam_1 = Convert.ToString(dr["vparam_1"].ToString());
                string vparam_2 = Convert.ToString(dr["vparam_2"].ToString());
                string iparam_1 = Convert.ToString(dr["iparam_1"].ToString());
                string iparam_2 = Convert.ToString(dr["iparam_2"].ToString());
                string idomain = Convert.ToString(dr["idomain"].ToString());
                string ioptype = Convert.ToString(1001);
                string iactionid = Convert.ToString(0);
                string iparam_3 = Convert.ToString(1);
                string ieventTime = Convert.ToString(dr["ieventTime"]);
                string iworldid = Convert.ToString(dr["iworldid"].ToString());
                string vuin = Convert.ToString(dr["openid"].ToString());
                int wdpid = Convert.ToInt32(dr["wdpid"].ToString());

                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("iappid", Convert.ToString(sdk.APPID));
                param.Add("idomain", idomain);
                param.Add("ioptype", ioptype);
                param.Add("iactionid", iactionid);
                param.Add("iworldid", iworldid);
                param.Add("vuin", vuin);
                param.Add("ieventTime", ieventTime);
                param.Add("iparam_1", iparam_1);
                param.Add("iparam_2", iparam_2);
                param.Add("vparam_1", vparam_1);
                param.Add("vparam_2", vparam_2);
                param.Add("iparam_3", iparam_3);
                if (wdpid == 14)
                {
                    param.Add("vparam_4", "tgp");
                }
                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/report.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    logstr += "OPEN_RECHARGE_LOG_TYPE  ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " token: " + vparam_1 + " iworldid:" + iworldid + "\r\n";
                    logstr += OpenApiV3.PrintRequest("", param, "POST") + "\r\n";
                    /*
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        sqlCon.NonQueryExec("update pay_token set syncret = 0 where token = '" + vparam_1.ToString() + "'");
                    }*/
                }
                else
                {
                    logstr += "OPEN_RECHARGE_LOG_TYPE Code: " + rs.Ret + " Msg: " + rs.Msg + " token: " + vparam_1 + " iworldid:" + iworldid + "\r\n";
                }
            }

            if (logstr.Length > 5)
            {
                LogHelper.WriteLog(logstr);
            }

        }
        //罗盘数据 消费日志推送
        public void notic_luopan_buy_log(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            string logstr = "";
            string errstr = "";
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string opopenid = Convert.ToString(dr["opopenid"].ToString());
                string serverid = Convert.ToString(dr["serverid"].ToString());
                string worldid = Convert.ToString(dr["worldid"].ToString());
                string userip = Convert.ToString(dr["userip"].ToString());
                string domain = Convert.ToString(dr["domain"].ToString());
                string buytime = Convert.ToString(dr["buytime"].ToString());
                string opuid = Convert.ToString(dr["opuid"].ToString());
                string itemid = Convert.ToString(dr["itemid"].ToString());
                string itemcnt = Convert.ToString(dr["itemcnt"].ToString());
                string modifyfee = Convert.ToString(dr["modifyfee"].ToString());
                string totalfee = Convert.ToString(dr["totalfee"].ToString());
                string level = Convert.ToString(dr["level"].ToString());
                string wdpid = Convert.ToString(dr["wdpid"].ToString());
                string svrip = Convert.ToString(localip);

                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("version", "1");
                param.Add("appid", Convert.ToString(sdk.APPID));//应用ID
                param.Add("userip", userip);
                param.Add("svrip", svrip);
                param.Add("time", buytime);
                param.Add("domain", domain);
                param.Add("worldid", worldid);
                param.Add("opuid", opuid);
                param.Add("opopenid", opopenid);
                param.Add("modifyfee", modifyfee);
                param.Add("itemtid", itemid);
                param.Add("itemtype", Convert.ToString(0));
                param.Add("itemcnt", itemcnt);
                param.Add("totalfee", totalfee);
                param.Add("level", level);
                param.Add("wdpid", wdpid);

                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/stat/report_consume.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    logstr += "SYNC_BUY_LOG_TYPE id = '" + id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " serverid:" + serverid + "\r\n";
                    logstr += OpenApiV3.PrintRequest("", param, "POST") + "\r\n";
                    //罗盘数据 消费日志推送
                    /*
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        string sql ="insert into log_report(type, userip, svrip, time,domain,worldid, opuid, opopenid,level,wdpid,itemid,itemcnt,fee,totalfee) values("
                            + 9 + ", " + Convert.ToUInt64(userip) + "," + Convert.ToUInt64(svrip) + "," + Convert.ToUInt64(buytime) + "," + Convert.ToUInt32(domain) + ","
                            + Convert.ToUInt32(worldid) + "," + Convert.ToUInt64(opuid) + ",'" + opopenid + "'," + Convert.ToUInt32(level) + "," + Convert.ToInt32(wdpid) + ","
                            + Convert.ToUInt32(itemid) + "," + Convert.ToUInt32(itemcnt) + ", " + Convert.ToUInt32(modifyfee) + ", " + Convert.ToUInt32(totalfee) + ")";

                        sqlCon.NonQueryExec(sql);
                    }
                     * */
                }
                else
                {
                    logstr += "SYNC_BUY_LOG_TYPE id = '" + id.ToString() + "'  ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " serverid:" + serverid + "\r\n";
                }
            }

            if (logstr.Length > 5)
            {
                LogHelper.WriteLog(logstr);
            }
        }
        //罗盘数据 玩家登出推送
        public void notic_luopan_quit_log(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            string logstr = "";
            string errstr = "";
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string opopenid = Convert.ToString(dr["opopenid"].ToString());
                string userip = Convert.ToString(dr["userip"].ToString());
                string logouttime = Convert.ToString(dr["logouttime"].ToString());
                //string logouttime = Convert.ToString(dataTable.Rows[n][4]);
                string onlinetime = Convert.ToString(dr["onlinetime"].ToString());
                string domain = Convert.ToString(dr["domain"].ToString());
                string opuid = Convert.ToString(dr["opuid"].ToString());
                string level = Convert.ToString(dr["level"].ToString());
                //int serverid = Convert.ToInt32(dataTable.Rows[n][9]);
                string wdpid = Convert.ToString(dr["wdpid"].ToString());
                string worldid = Convert.ToString(dr["worldid"].ToString());
                string svrip = Convert.ToString(localip);

                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("version", "1");
                param.Add("appid", Convert.ToString(sdk.APPID));//应用ID
                param.Add("userip", userip);
                param.Add("svrip", svrip);
                param.Add("time", logouttime);
                param.Add("domain", domain);
                param.Add("worldid", worldid);
                param.Add("opuid", opuid);
                param.Add("opopenid", opopenid);
                param.Add("onlinetime", onlinetime);
                param.Add("level", level);
                param.Add("wdpid", wdpid);
                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/stat/report_quit.php";
                //执行API 上报消费数据服务器 
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    logstr += "SYNC_QUIT_LOG_TYPE id = '" + id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " openid:" + opopenid + " worldid:" + worldid + " \r\n";
                    logstr += OpenApiV3.PrintRequest("", param, "POST") + "\r\n";

                    /*
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        string sql = "insert into log_report(type, userip, svrip, time,domain,worldid, opuid, opopenid,level,wdpid, onlinetime) values("
                            + 11 + ", " + Convert.ToUInt64(userip) + "," + Convert.ToUInt64(svrip) + "," + Convert.ToUInt64(logouttime) + "," + Convert.ToUInt32(domain) + ","
                            + Convert.ToUInt32(worldid) + "," + Convert.ToUInt64(opuid) + ",'" + opopenid + "'," + Convert.ToUInt32(level) + "," + Convert.ToInt32(wdpid) + ","
                            + Convert.ToUInt64(onlinetime) + ")";

                        sqlCon.NonQueryExec(sql);
                    }*/
                }
                else
                {
                    logstr += "SYNC_QUIT_LOG_TYPE id = '" + id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " openid:" + opopenid + " worldid:" + worldid + " \r\n";
                }
            }

            if (logstr.Length > 5)
            {
                LogHelper.WriteLog(logstr);
            }
        }
        /*游戏联盟 玩家登入数据
        public void notic_union_login_log(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            string logstr = "";
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = dr["id"].ToString();
                string userip = dr["ip"].ToString();
                string svrip = Convert.ToString(localip); 
                string time = dr["logintime"].ToString();
                int serverid = Convert.ToInt32(dr["serverid"].ToString());
                string worldid = Convert.ToString(serverid - svrid);
                string uid = dr["roleid"].ToString();
                string openid = dr["openid"].ToString();
                string level = dr["playerlevel"].ToString();
                string pf = dr["pf"].ToString();
                string openkey = dr["openkey"].ToString();
                string pfkey = dr["pfkey"].ToString();
                string x5sig = dr["x5sig"].ToString();
                string wdpid = dr["wdpid"].ToString();

                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("eventid", "login");
                param.Add("version", Convert.ToString(1));
                param.Add("userip", userip);
                param.Add("svrip", svrip);
                param.Add("time", time);
                param.Add("worldid", worldid);
                param.Add("uid", uid);
                param.Add("openid", openid);
                param.Add("level", level);
                param.Add("pf", pf);
                param.Add("openkey", openkey);
                param.Add("pfkey", pfkey);
                param.Add("x5sig", x5sig);
                param.Add("wdpid", wdpid); //微端标识
                
                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/wusp/report.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, true);
                if (rs.Ret != 0) //执行失败
                {
                        string msg = openid + "," + pf + "," + openkey + "," + pfkey; 
                        logstr += "游戏联盟登入数据日志上报失败 id = '" + id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " err: " + msg +"\n";
//                     using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
//                     {
//                         string msg = openid + "," + pf + "," + openkey + "," + pfkey; 
//                         logstr += "执行失败 id = '" + id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " err: " + msg "\n";
//                         //sqlCon.NonQueryExec("update log_logout set isreport = 0 where id = '" + id.ToString() + "'");
//                     }
                }
            }

            if (logstr.Length > 5)
            {
                LogHelper.WriteLog(logstr);
            } 
        }
         */
        //开平经分 创建角色
        public void notic_open_create_log(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            string logstr = "";
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];

                string account = Convert.ToString(dr["account"].ToString());
                string idomain = Convert.ToString(dr["domain"].ToString());
                string ioptype = Convert.ToString(0);
                string iactionid = Convert.ToString(0);
                string iworldid = Convert.ToString(dr["worldid"].ToString());
                string vuin = Convert.ToString(dr["openid"].ToString()); //openid
                string iuserip = Convert.ToString(dr["userip"].ToString());
                string ieventTime = Convert.ToString(dr["createtime"].ToString());
                string iroleId = Convert.ToString(dr["roleid"].ToString());
                string ijobId = Convert.ToString(dr["school"].ToString());
                //string via = Convert.ToString(dr["via"].ToString());
                //string wdpid = Convert.ToString(dr["wdpid"].ToString());
                int wdpid = Convert.ToInt32(dr["wdpid"].ToString()); //微端标识
                string vparam_4 = "";
                if (wdpid == 14)
                {
                    vparam_4 = "tgp";
                }

                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("iappid", Convert.ToString(sdk.APPID));
                param.Add("version", Convert.ToString(1));
                param.Add("idomain", idomain);
                param.Add("ioptype", ioptype);
                param.Add("iactionid", iactionid);
                param.Add("iworldid", iworldid);
                param.Add("vuin", vuin);
                param.Add("iuserip", iuserip);
                param.Add("ieventTime", ieventTime);
                param.Add("iroleId", iroleId);
                param.Add("ijobId", ijobId);
                param.Add("vparam_4", vparam_4); //微端标识

                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/report.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    logstr += "OPEN_CREATE_LOG_TYPE ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " vuin: " + vuin + " iworldid:" + iworldid + "\r\n";
                    logstr += OpenApiV3.PrintRequest("", param, "POST") + "\r\n";
                    /*
                     using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                     {
                         sqlCon.NonQueryExec("update t_u_createrole set isreport = 0 where account = '" + account.ToString() + "'");
                     }
                     * */
                }
                else
                {
                    logstr += "OPEN_CREATE_LOG_TYPE ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " vuin: " + vuin + " iworldid:" + iworldid + "\r\n";
                }
            }

            if (logstr.Length > 5)
            {
                LogHelper.WriteLog(logstr);
            }
        }
        //开平经分 角色登录
        public void notic_open_login_log(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            string logstr = "";
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                //
                string id = Convert.ToString(dr["id"].ToString());
                string idomain = Convert.ToString(dr["domain"].ToString());
                string ioptype = Convert.ToString(1);
                string iactionid = Convert.ToString(0);
                //int serverid = Convert.ToInt32(dr["serverid"].ToString());
                string iworldid = Convert.ToString(dr["worldid"].ToString());
                string vuin = Convert.ToString(dr["openid"].ToString());
                string iuserip = Convert.ToString(dr["userip"].ToString());
                string ieventTime = Convert.ToString(dr["logintime"].ToString());
                string iroleId = Convert.ToString(dr["roleid"].ToString());
                string ijobId = Convert.ToString(dr["school"].ToString());
                string ilevel = Convert.ToString(dr["level"].ToString());
                string vparam_1 = Convert.ToString(0); //角色经验
                string iparam_16 = Convert.ToString(dr["curpoints"].ToString()); //元宝
                string iparam_17 = Convert.ToString(dr["curbindpoints"].ToString()); //绑定元宝
                string iparam_18 = Convert.ToString(0); //0
                string iparam_19 = Convert.ToString(dr["curgiftcoins"].ToString()); //礼金
                string iparam_20 = Convert.ToString(dr["createtime"].ToString());
                string vparam_19 = Convert.ToString(dr["via"].ToString());
                string iparam_1 = Convert.ToString(dr["allonlinetime"].ToString()); //公共在线时长
                int wdpid = Convert.ToInt32(dr["wdpid"].ToString());
                string vparam_4 = "";
                if (wdpid == 14)
                {
                    vparam_4 = "tgp";
                }

                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("iappid", Convert.ToString(sdk.APPID));
                param.Add("version", Convert.ToString(1));
                param.Add("idomain", idomain);
                param.Add("ioptype", ioptype);
                param.Add("iactionid", iactionid);
                param.Add("iworldid", iworldid);
                param.Add("vuin", vuin);
                param.Add("iuserip", iuserip);
                param.Add("ieventTime", ieventTime);
                param.Add("iroleId", iroleId);
                param.Add("ijobId", ijobId);
                param.Add("ilevel", ilevel);
                param.Add("vparam_1", vparam_1);
                param.Add("iparam_16", iparam_16);
                param.Add("iparam_17", iparam_17);
                param.Add("iparam_18", iparam_18);
                param.Add("iparam_19", iparam_19);
                param.Add("iparam_20", iparam_20);
                param.Add("vparam_19", vparam_19);
                param.Add("iparam_1", iparam_1);
                param.Add("vparam_4", vparam_4); //微端标识

                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/report.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    logstr += "OPEN_LOGIN_LOG_TYPE id = '" + id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " vuin: " + vuin + " iworldid " + iworldid + "\r\n";
                    logstr += OpenApiV3.PrintRequest("", param, "POST") + "\r\n";
                    /*
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        sqlCon.NonQueryExec("update log_reglogin set isreport = 0 where id = '" + id.ToString() + "'");
                    }
                     * */
                }
                else
                {
                    logstr += "OPEN_LOGIN_LOG_TYPE id = '" + id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " vuin: " + vuin + " iworldid " + iworldid + "\r\n";
                }
            }

            if (logstr.Length > 5)
            {
                LogHelper.WriteLog(logstr);
            }
        }
        //开平经分 角色登出
        public void notic_open_quit_log(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            string logstr = "";
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string idomain = Convert.ToString(dr["domain"].ToString());
                string ioptype = Convert.ToString(1);
                string iactionid = Convert.ToString(1);
                string iworldid = Convert.ToString(dr["worldid"].ToString());
                string vuin = Convert.ToString(dr["opopenid"].ToString());
                string iuserip = Convert.ToString(dr["userip"].ToString());
                string ieventTime = Convert.ToString(dr["logouttime"].ToString());
                string iroleId = Convert.ToString(dr["opuid"].ToString());
                string ijobId = Convert.ToString(dr["school"].ToString());
                string ilevel = Convert.ToString(dr["level"].ToString());
                //string wdpid =Convert.ToString(dr["wdpid"].ToString());
                string iparam_16 = Convert.ToString(dr["point"].ToString());  //角色元宝
                string iparam_17 = Convert.ToString(dr["curbindpoints"]).ToString(); //角色绑定元宝
                string iparam_18 = Convert.ToString(0);
                string iparam_19 = Convert.ToString(dr["curgiftcoins"].ToString()); //角色礼金
                string onlinetime = Convert.ToString(dr["onlinetime"].ToString());
                UInt64 uonlinetime = Convert.ToUInt64(onlinetime);
                UInt64 logouttime = Convert.ToUInt64(ieventTime);
                string iparam_1 = Convert.ToString(logouttime - uonlinetime); //登录时间戳
                string iparam_20 = Convert.ToString(onlinetime); //在线时长
                int wdpid = Convert.ToInt32(dr["wdpid"].ToString()); //微端标识
                string vparam_4 = "";
                if (wdpid == 14)
                {
                    vparam_4 = "tgp";
                }
                string serverid = Convert.ToString(dr["serverid"].ToString());

                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("iappid", Convert.ToString(sdk.APPID));
                param.Add("version", Convert.ToString(1));
                param.Add("idomain", idomain);
                param.Add("ioptype", ioptype);
                param.Add("iactionid", iactionid);
                param.Add("iworldid", iworldid);
                param.Add("vuin", vuin);
                param.Add("iuserip", iuserip);
                param.Add("ieventTime", ieventTime);
                param.Add("iroleId", iroleId);
                param.Add("ijobId", ijobId);
                param.Add("ilevel", ilevel);
                // param.Add("vparam_1", vparam_1);
                param.Add("iparam_16", iparam_16);
                param.Add("iparam_17", iparam_17);
                param.Add("iparam_18", iparam_18);
                param.Add("iparam_19", iparam_19);
                param.Add("iparam_20", iparam_20);
                param.Add("iparam_1", iparam_1);
                param.Add("vparam_4", vparam_4); //微端标识

                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/report.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    logstr += "OPEN_QUIT_LOG_TYPE id = '" + id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " vuin: " + vuin + " serverid " + serverid + "\r\n";
                    logstr += OpenApiV3.PrintRequest("", param, "POST") + "\r\n";
                    /*
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        string sql = "insert into log_report(type, userip, time, domain,worldid, opuid, opopenid,school, level,wdpid,onlinetime,point,bpoint,gcoin) values("
                            + 12 + ", " + Convert.ToUInt64(iuserip) + "," + Convert.ToUInt64(logouttime) + "," + Convert.ToUInt64(idomain) + "," + Convert.ToUInt32(iworldid) + ","
                            + Convert.ToUInt32(iroleId) + ",'" + vuin + "'," + Convert.ToUInt32(ijobId) + "," + Convert.ToInt32(ilevel) + "," + Convert.ToInt32(wdpid) + "," + Convert.ToUInt64(onlinetime) + ","
                            + Convert.ToUInt64(iparam_16) + "," + Convert.ToUInt64(iparam_17) + "," + Convert.ToUInt64(iparam_19) + ")";

                        sqlCon.NonQueryExec(sql);
                    }*/
                }
                else
                {
                    logstr += "OPEN_QUIT_LOG_TYPE id = '" + id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " vuin: " + vuin + " serverid " + serverid + "\r\n";
                }
            }

            if (logstr.Length > 5)
            {
                LogHelper.WriteLog(logstr);
            }
        }
        //开平经分 商城购买日志
        public void notic_open_buy_log(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            string logstr = "";
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string idomain = Convert.ToString(dr["domain"].ToString());
                string ioptype = "3";
                string iactionid = "0";
                string iworldid = Convert.ToString(dr["worldid"].ToString());
                string vuin = Convert.ToString(dr["opopenid"].ToString());
                string ilevel = Convert.ToString(dr["level"].ToString());
                string iuserip = Convert.ToString(dr["userip"].ToString());
                string ieventTime = Convert.ToString(dr["buytime"].ToString());
                string iroleId = Convert.ToString(dr["opuid"].ToString());
                string iparam_1 = Convert.ToString(1);
                string iparam_2 = Convert.ToString(dr["modifyfee"].ToString());//支付消耗
                string iparam_3 = "0";
                string iparam_16 = Convert.ToString(dr["itemid"].ToString());//商品ID
                string vparam_1 = Convert.ToString(dr["info"].ToString());
                string iparam_4 = Convert.ToString(dr["itemcnt"].ToString()); //商品数量
                //
                string serverid = Convert.ToString(dr["serverid"].ToString()); //服务器ID
                string vreserve_1 = serverid + "_" + id;

                int wdpid = Convert.ToInt32(dr["wdpid"].ToString()); //微端标识
                string vparam_4 = "";
                if (wdpid == 14)
                {
                    vparam_4 = "tgp";
                }


                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("iappid", Convert.ToString(sdk.APPID));//应用ID
                param.Add("version", Convert.ToString(1));
                param.Add("idomain", idomain); //平台ID
                param.Add("ioptype", ioptype); //类型(3)
                param.Add("iactionid", iactionid); //子类型(0)
                param.Add("iworldid", iworldid); //大区id
                param.Add("vuin", vuin); //openid
                param.Add("ilevel", ilevel); //角色等级
                param.Add("iuserip", iuserip); //客户端ip主机字节序
                param.Add("ieventTime", ieventTime); //时间 unix 时间戳
                param.Add("iroleId", iroleId);      //角色id          
                param.Add("iparam_1", iparam_1); //支付类型
                param.Add("iparam_2", iparam_2); //支付消耗
                param.Add("iparam_3", iparam_3); //商品类型
                param.Add("iparam_16", iparam_16);  //商品ID
                param.Add("vparam_1", vparam_1); //商品名称
                param.Add("iparam_4", iparam_4); //商品数量
                param.Add("vreserve_1", vreserve_1); //流水号
                param.Add("vparam_4", vparam_4); //微端标识

                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/report.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    logstr += "OPEN_BUY_LOG_TYPE id = '" + id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " vuin: " + vuin + " serverid " + serverid + "\r\n";
                    logstr += OpenApiV3.PrintRequest("", param, "POST") + "\r\n";
                    /*
                     using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                     {
                         string sql = "insert into log_report(type, userip, time,domain,worldid, opuid, opopenid,level,wdpid,itemid,itemcnt,iteminfo,fee,serial) values("
                                + 10 + ", " + Convert.ToUInt64(iuserip) + "," + Convert.ToUInt64(ieventTime) + "," + Convert.ToUInt32(idomain) + ","
                                + Convert.ToUInt32(iworldid) + "," + Convert.ToUInt64(iroleId) + ",'" + vuin + "'," + Convert.ToUInt32(ilevel) + "," 
                                + Convert.ToInt32(wdpid) + "," + Convert.ToUInt32(iparam_16) + "," + Convert.ToUInt32(vparam_4) + ", '" + vparam_1 + "',"
                                + Convert.ToUInt32(iparam_2) + ", '" +(vreserve_1) + "')";

                         sqlCon.NonQueryExec(sql);
                     }
                     * */
                }
                else
                {
                    logstr += "OPEN_BUY_LOG_TYPE id = '" + id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + "vuin: " + vuin + "  serverid " + serverid + "\r\n";
                }
            }

            if (logstr.Length > 5)
            {
                LogHelper.WriteLog(logstr);
            }
        }
        //在线角色数量统计
        public void notic_open_online_log(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            string logstr = "";
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string idomain = Convert.ToString(0);
                string ioptype = Convert.ToString(2);
                string iactionid = Convert.ToString(0);
                //int serverid = Convert.ToInt32(dataTable.Rows[n][1]);
                string iworldid = Convert.ToString(dr["worldid"].ToString());
                string ieventTime = Convert.ToString(dr["ieventtime"].ToString());
                string iparam_1 = Convert.ToString(dr["onlinenum"].ToString());
                string serverid = Convert.ToString(dr["serverid"].ToString());
                //string wdpid = Convert.ToString(dataTable.Rows[n][7]);

                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("iappid", Convert.ToString(sdk.APPID));
                param.Add("version", Convert.ToString(1));
                param.Add("idomain", idomain);
                param.Add("ioptype", ioptype);
                param.Add("iactionid", iactionid);
                param.Add("iworldid", iworldid);
                param.Add("ieventTime", ieventTime);
                param.Add("iparam_1", iparam_1);
                //param.Add("wdpid", wdpid); //微端标识
                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/report.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    logstr += "OPEN_ONLINE_LOG_TYPE id = '" + id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " serverid: " + serverid + "\r\n";
                    logstr += OpenApiV3.PrintRequest("", param, "POST") + "\r\n";
                    /*
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        sqlCon.NonQueryExec("update log_online set isreport = 0 where id = '" + id.ToString() + "'");
                    }
                    **/
                }
                else
                {
                    logstr += "OPEN_ONLINE_LOG_TYPE id = '" + id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " serverid: " + serverid + "\r\n";
                }
            }

            if (logstr.Length > 5)
            {
                LogHelper.WriteLog(logstr);
            }
        }
        //QQ游戏大厅 登出日志上报
        public void notic_qqgame_quit_log(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            //QQ大厅 数据上报
            DataRow[] dd = dataTable.Select("pf='qqgame'");
            DataTable dt;
            if (dd.Length > 0)
            {
                dt = ToDataTable(dd);
            }
            else{
                return ;
            }

            string logstr = "";
            int rows = dt.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dt.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string openid = Convert.ToString(dr["opopenid"].ToString());
                string openkey = Convert.ToString(dr["openkey"].ToString());
                //string appid
                string serveridstr = Convert.ToString(dr["serverid"]).ToString();
                string pf = "qqgame";
                string userip = Convert.ToString(dr["userip"].ToString());
                string roleid = Convert.ToString(dr["opuid"].ToString());
                UInt32 serverid = Convert.ToUInt32(dr["serverid"].ToString()); //zoneid
                string zoneid = Convert.ToString(serverid - 7010000);

                string infotype = "2";
                UInt64 onlinetime = Convert.ToUInt64(dr["onlinetime"].ToString());
                UInt64 logouttime = Convert.ToUInt64(dr["logouttime"].ToString());
                string value1 = Convert.ToString(logouttime - onlinetime); //登录时间戳
                string value2 = Convert.ToString(logouttime); //登出时间
                string value3 = Convert.ToString(onlinetime); //在线时长

                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("userip", userip);
                param.Add("roleid", roleid);
                param.Add("zoneid", zoneid);
                param.Add("infotype", infotype);
                param.Add("value1", value1); //登录时间
                param.Add("value2", value2); //登出时间
                param.Add("value3", value3); //在线时长
                //公共参数
                param.Add("openid", openid.ToUpper());
                param.Add("openkey", openkey);
                param.Add("pf", pf);

                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/v3/message/openreport_quit ";
                //执行API 上报数据
                RstArray rs = sdk.Api(script_name, param);
                if (rs.Ret != 0) //执行失败
                {
                    logstr += "QQGAME_QUIT_LOG_TYPE id = '" + id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " openid: " + openid + " serverid: " + serveridstr + "\r\n";
                    logstr += OpenApiV3.PrintRequest("", param, "POST") + "\r\n";
                }
                else
                {
                    logstr += "QQGAME_QUIT_LOG_TYPE id = '" + id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " openid: " + openid + " serverid: " + serveridstr + "\r\n";
                }
            }
            if (logstr.Length > 5)
            {
                LogHelper.WriteLog(logstr);
            }
        }

        //罗盘 在线角色数量统计
        public void notic_luopan_online_log(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            string logstr = "";
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string idomain = Convert.ToString(0);
                string iworldid = Convert.ToString(dr["worldid"].ToString());
                string ieventTime = Convert.ToString(dr["ieventtime"].ToString());
                string iparam_1 = Convert.ToString(dr["onlinenum"].ToString());
                string serverid = Convert.ToString(dr["serverid"].ToString());
                //string wdpid = Convert.ToString(dataTable.Rows[n][7]);

                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("appid", Convert.ToString(sdk.APPID));
                param.Add("version", Convert.ToString(1));
                param.Add("domain", idomain);
                param.Add("worldid", iworldid);
                param.Add("time", ieventTime);
                param.Add("user_num", iparam_1);
                //param.Add("wdpid", wdpid); //微端标识
                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/stat/report_online.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    logstr += "LPAN_ONLINE_LOG_TYPE id = '" + id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " serverid: " + serverid + "\r\n";
                    logstr += OpenApiV3.PrintRequest("", param, "POST") + "\r\n";
                    /*
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        sqlCon.NonQueryExec("update log_online set isreport = 0 where id = '" + id.ToString() + "'");
                    }
                    **/
                }
                else
                {
                    logstr += "LPAN_ONLINE_LOG_TYPE id = '" + id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + " serverid: " + serverid + "\r\n";
                }
            }

            if (logstr.Length > 5)
            {
                LogHelper.WriteLog(logstr);
            }
        }
#endregion

        /////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////////////////
#region 经常卡死


        //1.罗盘注册,2.罗盘登录,3.罗盘接受邀请注册,4.罗盘邀请他人注册,5.罗盘支付充值,
        //6.联盟注册,7.联盟登录,8.联盟支付充值,9.罗盘消费日志, 10.开平消费日志
        //11.罗盘登出日志 12.开平登出日志
        //上传失败日志重新发送
        //注册
        public void notic_sync_register_elog(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string version = "1";
                string appid = Convert.ToString(dr["appid"].ToString());
                string userip = Convert.ToString(dr["userip"].ToString());
                string svrip = Convert.ToString(dr["svrip"].ToString());
                string time = Convert.ToString(dr["time"].ToString());
                string domain = Convert.ToString(dr["domain"].ToString());
                string worldid = Convert.ToString(dr["worldid"].ToString());
                string opuid = Convert.ToString(dr["opuid"].ToString());
                string opopenid = Convert.ToString(dr["opopenid"].ToString());
                string wdpid = Convert.ToString(dr["wdpid"].ToString());
                //
                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("version", version);
                param.Add("appid", appid);
                param.Add("userip", userip);
                param.Add("svrip", svrip);
                param.Add("time", time);
                param.Add("domain", domain);
                param.Add("worldid", worldid);
                param.Add("opuid", opuid);
                param.Add("opopenid", opopenid);
                param.Add("wdpid", wdpid);

                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/stat/report_register.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        sqlCon.NonQueryExec("update log_report set isreport = 0 where id = '" + id.ToString() + "'");
                    }
                }
            }
        }
        //登录
        public void notic_sync_login_elog(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string version = "1";
                string appid = Convert.ToString(dr["appid"].ToString());
                string userip = Convert.ToString(dr["userip"].ToString());
                string svrip = Convert.ToString(dr["svrip"].ToString());
                string time = Convert.ToString(dr["time"].ToString());
                string domain = Convert.ToString(dr["domain"].ToString());
                string worldid = Convert.ToString(dr["worldid"].ToString());
                string opuid = Convert.ToString(dr["opuid"].ToString());
                string opopenid = Convert.ToString(dr["opopenid"].ToString());
                string level = Convert.ToString(dr["level"].ToString());
                string wdpid = Convert.ToString(dr["wdpid"].ToString());
                //
                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("version", version);
                param.Add("appid", appid);
                param.Add("userip", userip);
                param.Add("svrip", svrip);
                param.Add("time", time);
                param.Add("domain", domain);
                param.Add("worldid", worldid);
                param.Add("opuid", opuid);
                param.Add("opopenid", opopenid);
                param.Add("level", level);
                param.Add("wdpid", wdpid);

                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/stat/report_login.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        sqlCon.NonQueryExec("update log_report set isreport = 0 where id = '" + id.ToString() + "'");
                    }
                }
            }
        }
        //被邀请
        public void notic_sync_accept_elog(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string version = "1";
                string appid = Convert.ToString(dr["appid"].ToString());
                string userip = Convert.ToString(dr["userip"].ToString());
                string svrip = Convert.ToString(dr["svrip"].ToString());
                string time = Convert.ToString(dr["time"].ToString());
                string domain = Convert.ToString(dr["domain"].ToString());
                string worldid = Convert.ToString(dr["worldid"].ToString());
                string opuid = Convert.ToString(dr["opuid"].ToString());
                string opopenid = Convert.ToString(dr["opopenid"].ToString());
                //string level = Convert.ToString(dr["level"].ToString());
                string wdpid = Convert.ToString(dr["wdpid"].ToString());
                //
                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("version", version);
                param.Add("appid", appid);
                param.Add("userip", userip);
                param.Add("svrip", svrip);
                param.Add("time", time);
                param.Add("domain", domain);
                param.Add("worldid", worldid);
                param.Add("opuid", opuid);
                param.Add("opopenid", opopenid);
                //param.Add("level", level);
                param.Add("wdpid", wdpid);

                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/stat/report_accept.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        sqlCon.NonQueryExec("update log_report set isreport = 0 where id = '" + id.ToString() + "'");
                    }
                }
            }
        }
        //邀请
        public void notic_sync_invite_elog(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string version = "1";
                string appid = Convert.ToString(dr["appid"].ToString());
                string userip = Convert.ToString(dr["userip"].ToString());
                string svrip = Convert.ToString(dr["svrip"].ToString());
                string time = Convert.ToString(dr["time"].ToString());
                string domain = Convert.ToString(dr["domain"].ToString());
                string worldid = Convert.ToString(dr["worldid"].ToString());
                string opuid = Convert.ToString(dr["opuid"].ToString());
                string opopenid = Convert.ToString(dr["opopenid"].ToString());
                string touid = Convert.ToString(dr["touid"].ToString());
                string toopenid = Convert.ToString(dr["toopenid"].ToString());
                string wdpid = Convert.ToString(dr["wdpid"].ToString());
                //
                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("version", version);
                param.Add("appid", appid);
                param.Add("userip", userip);
                param.Add("svrip", svrip);
                param.Add("time", time);
                param.Add("domain", domain);
                param.Add("worldid", worldid);
                param.Add("opuid", opuid);
                param.Add("opopenid", opopenid);
                param.Add("touid", touid);
                param.Add("toopenid", toopenid);
                param.Add("wdpid", wdpid);

                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/stat/report_invite.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        sqlCon.NonQueryExec("update log_report set isreport = 0 where id = '" + id.ToString() + "'");
                    }
                }
            }
        }
        //支付充值
        public void notic_sync_paycharge_elog(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string version = "1";
                string appid = Convert.ToString(dr["appid"].ToString());
                string userip = Convert.ToString(dr["userip"].ToString());
                string svrip = Convert.ToString(dr["svrip"].ToString());
                string time = Convert.ToString(dr["time"].ToString());
                string domain = Convert.ToString(dr["domain"].ToString());
                string worldid = Convert.ToString(dr["worldid"].ToString());
                string opuid = Convert.ToString(dr["opuid"].ToString());
                string opopenid = Convert.ToString(dr["opopenid"].ToString());
                string modifyfee = Convert.ToString(dr["fee"].ToString());
                string touid = Convert.ToString(dr["touid"].ToString());
                string toopenid = Convert.ToString(dr["toopenid"].ToString());
                string itemid = Convert.ToString(dr["itemid"].ToString());
                string itemcnt = Convert.ToString(dr["itemcnt"].ToString());
                string level = Convert.ToString(dr["level"].ToString());
                string wdpid = Convert.ToString(dr["wdpid"].ToString());
                //
                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("version", version);
                param.Add("appid", appid);
                param.Add("userip", userip);
                param.Add("svrip", svrip);
                param.Add("time", time);
                param.Add("domain", domain);
                param.Add("worldid", worldid);
                param.Add("opuid", opuid);
                param.Add("opopenid", opopenid);
                param.Add("modifyfee", modifyfee);
                param.Add("touid", touid);
                param.Add("toopenid", toopenid);
                param.Add("itemid", itemid);
                param.Add("itemcnt", itemcnt);
                param.Add("level", level);
                param.Add("wdpid", wdpid);

                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/stat/report_recharge.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        sqlCon.NonQueryExec("update log_report set isreport = 0 where id = '" + id.ToString() + "'");
                    }
                }
            }
        }
        //消费
        public void notic_sync_buy_elog(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string version = "1";
                string appid = Convert.ToString(dr["appid"].ToString());
                string userip = Convert.ToString(dr["userip"].ToString());
                string svrip = Convert.ToString(dr["svrip"].ToString());
                string time = Convert.ToString(dr["time"].ToString());
                string domain = Convert.ToString(dr["domain"].ToString());
                string worldid = Convert.ToString(dr["worldid"].ToString());
                string opuid = Convert.ToString(dr["opuid"].ToString());
                string opopenid = Convert.ToString(dr["opopenid"].ToString());
                string modifyfee = Convert.ToString(dr["fee"].ToString());
                string touid = Convert.ToString(dr["touid"].ToString());
                string toopenid = Convert.ToString(dr["toopenid"].ToString());
                string itemid = Convert.ToString(dr["itemid"].ToString());
                string itemcnt = Convert.ToString(dr["itemcnt"].ToString());
                string level = Convert.ToString(dr["level"].ToString());
                string wdpid = Convert.ToString(dr["wdpid"].ToString());
                //
                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("version", version);
                param.Add("appid", appid);
                param.Add("userip", userip);
                param.Add("svrip", svrip);
                param.Add("time", time);
                param.Add("domain", domain);
                param.Add("worldid", worldid);
                param.Add("opuid", opuid);
                param.Add("opopenid", opopenid);
                param.Add("modifyfee", modifyfee);
                param.Add("touid", touid);
                param.Add("toopenid", toopenid);
                param.Add("itemid", itemid);
                param.Add("itemcnt", itemcnt);
                param.Add("level", level);
                param.Add("wdpid", wdpid);

                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/stat/report_consume.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        sqlCon.NonQueryExec("update log_report set isreport = 0 where id = '" + id.ToString() + "'");
                    }
                }
            }
        }
        //退出
        public void notic_sync_quit_elog(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string version = "1";
                string appid = Convert.ToString(dr["appid"].ToString());
                string userip = Convert.ToString(dr["userip"].ToString());
                string svrip = Convert.ToString(dr["svrip"].ToString());
                string time = Convert.ToString(dr["time"].ToString());
                string domain = Convert.ToString(dr["domain"].ToString());
                string worldid = Convert.ToString(dr["worldid"].ToString());
                string opuid = Convert.ToString(dr["opuid"].ToString());
                string opopenid = Convert.ToString(dr["opopenid"].ToString());
                string onlinetime = Convert.ToString(dr["onlinetime"].ToString());
                string level = Convert.ToString(dr["level"].ToString());
                string wdpid = Convert.ToString(dr["wdpid"].ToString());
                //
                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("version", version);
                param.Add("appid", appid);
                param.Add("userip", userip);
                param.Add("svrip", svrip);
                param.Add("time", time);
                param.Add("domain", domain);
                param.Add("worldid", worldid);
                param.Add("opuid", opuid);
                param.Add("opopenid", opopenid);
                param.Add("onlinetime", onlinetime);
                param.Add("level", level);
                param.Add("wdpid", wdpid);

                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/stat/report_quit.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        sqlCon.NonQueryExec("update log_report set isreport = 0 where id = '" + id.ToString() + "'");
                    }
                }
            }
        }
        //联盟游戏注册
        public void notic_union_register_elog(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string version = "1";
                string appid = Convert.ToString(dr["appid"].ToString());
                string userip = Convert.ToString(dr["userip"].ToString());
                string svrip = Convert.ToString(dr["svrip"].ToString());
                string time = Convert.ToString(dr["time"].ToString());
                //string domain =  Convert.ToString(dr["domain"].ToString());
                string worldid = Convert.ToString(dr["worldid"].ToString());
                string uid = Convert.ToString(dr["opuid"].ToString());
                string openid = Convert.ToString(dr["opopenid"].ToString());
                string pf = Convert.ToString(dr["pf"].ToString());
                string openkey = Convert.ToString(dr["openkey"].ToString());
                string pfkey = Convert.ToString(dr["pfkey"].ToString());
                string x5sig = Convert.ToString(dr["x5sig"].ToString());
                string wdpid = Convert.ToString(dr["wdpid"].ToString());
                //
                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("eventid", "register");
                param.Add("appid", appid);
                param.Add("version", version);
                param.Add("userip", userip);
                param.Add("svrip", svrip);
                param.Add("time", time);
                //param.Add("domain", domain);
                param.Add("worldid", worldid);
                param.Add("uid", uid);
                param.Add("openid", openid);
                param.Add("pf", pf);
                param.Add("openkey", openkey);
                param.Add("pfkey", pfkey);
                param.Add("x5sig", x5sig);
                param.Add("wdpid", wdpid);

                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/wusp/report.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        sqlCon.NonQueryExec("update log_report set isreport = 0 where id = '" + id.ToString() + "'");
                    }
                }
            }

        }
        //游戏联盟 登录
        public void notic_union_login_elog(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string version = "1";
                string appid = Convert.ToString(dr["appid"].ToString());
                string userip = Convert.ToString(dr["userip"].ToString());
                string svrip = Convert.ToString(dr["svrip"].ToString());
                string time = Convert.ToString(dr["time"].ToString());
                //string domain =  Convert.ToString(dr["domain"].ToString());
                string worldid = Convert.ToString(dr["worldid"].ToString());
                string uid = Convert.ToString(dr["opuid"].ToString());
                string openid = Convert.ToString(dr["opopenid"].ToString());
                string level = Convert.ToString(dr["level"].ToString());
                string pf = Convert.ToString(dr["pf"].ToString());
                string openkey = Convert.ToString(dr["openkey"].ToString());
                string pfkey = Convert.ToString(dr["pfkey"].ToString());
                string x5sig = Convert.ToString(dr["x5sig"].ToString());
                string wdpid = Convert.ToString(dr["wdpid"].ToString());
                //
                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("eventid", "login");
                param.Add("appid", appid);
                param.Add("version", version);
                param.Add("userip", userip);
                param.Add("svrip", svrip);
                param.Add("time", time);
                //param.Add("domain", domain);
                param.Add("worldid", worldid);
                param.Add("uid", uid);
                param.Add("openid", openid);
                param.Add("level", level);
                param.Add("pf", pf);
                param.Add("openkey", openkey);
                param.Add("pfkey", pfkey);
                param.Add("x5sig", x5sig);
                param.Add("wdpid", wdpid);

                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/wusp/report.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        sqlCon.NonQueryExec("update log_report set isreport = 0 where id = '" + id.ToString() + "'");
                    }
                }
            }
        }
        //游戏联盟充值
        public void notic_union_paycharge_elog(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string version = "1";
                string appid = Convert.ToString(dr["appid"].ToString());
                string userip = Convert.ToString(dr["userip"].ToString());
                string svrip = Convert.ToString(dr["svrip"].ToString());
                string time = Convert.ToString(dr["time"].ToString());
                //string domain =  Convert.ToString(dr["domain"].ToString());
                string worldid = Convert.ToString(dr["worldid"].ToString());
                string uid = Convert.ToString(dr["opuid"].ToString());
                string openid = Convert.ToString(dr["opopenid"].ToString());
                string touid = Convert.ToString(dr["toopuid"].ToString());
                string toopenid = Convert.ToString(dr["toopopenid"].ToString());
                string pf = Convert.ToString(dr["pf"].ToString());
                string x5sig = Convert.ToString(dr["x5sig"].ToString());
                string iteminfo = Convert.ToString(dr["iteminfo"].ToString());
                string fee = Convert.ToString(dr["fee"].ToString());
                string coin = Convert.ToString(dr["coin"].ToString());
                string ticket = Convert.ToString(dr["ticket"].ToString());
                string serial = Convert.ToString(dr["serial"].ToString());
                string level = Convert.ToString(dr["level"].ToString());
                //string openkey = Convert.ToString(dr["openkey"].ToString());
                //string pfkey = Convert.ToString(dr["pfkey"].ToString());
                string wdpid = Convert.ToString(dr["wdpid"].ToString());
                //
                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("eventid", "buy");
                param.Add("appid", appid);
                param.Add("version", version);
                param.Add("userip", userip);
                param.Add("svrip", svrip);
                param.Add("time", time);
                //param.Add("domain", domain);
                param.Add("worldid", worldid);
                param.Add("uid", uid);
                param.Add("openid", openid);
                param.Add("touid", touid);
                param.Add("toopenid", toopenid);
                param.Add("pf", pf);
                param.Add("x5sig", x5sig);
                param.Add("iteminfo", iteminfo);
                param.Add("fee", fee);
                param.Add("coin", coin);
                param.Add("ticket", ticket);
                param.Add("serial", serial);
                //param.Add("openkey", openkey);
                //param.Add("pfkey", pfkey);

                param.Add("level", level);
                param.Add("wdpid", wdpid);

                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/wusp/report.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        sqlCon.NonQueryExec("update log_report set isreport = 0 where id = '" + id.ToString() + "'");
                    }
                }
            }
        }
        //开平消费 
        public void notic_open_buy_elog(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string idomain = Convert.ToString(dr["domain"].ToString());
                string ioptype = "3";
                string iactionid = "0";
                string iworldid = Convert.ToString(dr["worldid"].ToString());
                string vuin = Convert.ToString(dr["opopenid"].ToString());
                string ilevel = Convert.ToString(dr["level"].ToString());
                string iuserip = Convert.ToString(dr["userip"].ToString());
                string ieventTime = Convert.ToString(dr["time"].ToString());
                string iroleId = Convert.ToString(dr["opuid"].ToString());
                string iparam_1 = Convert.ToString(1);
                string iparam_2 = Convert.ToString(dr["fee"].ToString());//支付消耗
                string iparam_3 = "0";
                string iparam_16 = Convert.ToString(dr["itemid"].ToString());//商品ID
                string vparam_1 = Convert.ToString(dr["iteminfo"].ToString());
                string iparam_4 = Convert.ToString(dr["itemcnt"].ToString()); //商品数量
                string vreserve_1 = Convert.ToString(dr["serial"].ToString()); //流水号
                int wdpid = Convert.ToInt32(dr["wdpid"].ToString());
                string vparam_4 = "";
                if (wdpid == 14)
                {
                    vparam_4 = "tgp";
                }

                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("iappid", Convert.ToString(sdk.APPID));//应用ID
                param.Add("version", Convert.ToString(1));
                param.Add("idomain", idomain); //平台ID
                param.Add("ioptype", ioptype); //类型(3)
                param.Add("iactionid", iactionid); //子类型(0)
                param.Add("iworldid", iworldid); //大区id
                param.Add("vuin", vuin); //openid
                param.Add("ilevel", ilevel); //角色等级
                param.Add("iuserip", iuserip); //客户端ip主机字节序
                param.Add("ieventTime", ieventTime); //时间 unix 时间戳
                param.Add("iroleId", iroleId);      //角色id          
                param.Add("iparam_1", iparam_1); //支付类型
                param.Add("iparam_2", iparam_2); //支付消耗
                param.Add("iparam_3", iparam_3); //商品类型
                param.Add("iparam_16", iparam_16);  //商品ID
                param.Add("vparam_1", vparam_1); //商品名称
                param.Add("iparam_4", iparam_4); //商品数量
                param.Add("vreserve_1", vreserve_1); //流水号
                param.Add("vparam_4", vparam_4); //微端标识

                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/report.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        sqlCon.NonQueryExec("update log_report set isreport = 0 where id = '" + id.ToString() + "'");
                    }
                }
            }
        }
        //开平退出
        public void notic_open_quit_elog(GameDbInfo dbInfo, DataTable dataTable, OpenApiV3 sdk)
        {
            int rows = dataTable.Rows.Count;
            for (int n = 0; n < rows; n++)
            {
                DataRow dr = dataTable.Rows[n];
                string id = Convert.ToString(dr["id"].ToString());
                string idomain = Convert.ToString(dr["domain"].ToString());
                string ioptype = Convert.ToString(1);
                string iactionid = Convert.ToString(1);
                string iworldid = Convert.ToString(dr["worldid"].ToString());
                string vuin = Convert.ToString(dr["opopenid"].ToString());
                string iuserip = Convert.ToString(dr["userip"].ToString());
                string ieventTime = Convert.ToString(dr["time"].ToString());
                string iroleId = Convert.ToString(dr["opuid"].ToString());
                string ijobId = Convert.ToString(dr["school"].ToString());
                string ilevel = Convert.ToString(dr["level"].ToString());
                //string wdpid = Convert.ToString(dr["wdpid"].ToString());
                string iparam_16 = Convert.ToString(dr["point"].ToString());  //角色元宝
                string iparam_17 = Convert.ToString(dr["bpoint"]).ToString(); //角色绑定元宝
                string iparam_18 = Convert.ToString(0);
                string iparam_19 = Convert.ToString(dr["gcoin"].ToString()); //角色礼金
                UInt64 onlinetime = Convert.ToUInt64(dr["onlinetime"].ToString());
                UInt64 logouttime = Convert.ToUInt64(ieventTime);
                string iparam_1 = Convert.ToString(logouttime - onlinetime); //登录时间戳
                string iparam_20 = Convert.ToString(onlinetime); //在线时长

                int wdpid = Convert.ToInt32(dr["wdpid"].ToString()); //微端标识
                string vparam_4 = "";
                if (wdpid == 14)
                {
                    vparam_4 = "tgp";
                }

                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add("iappid", Convert.ToString(sdk.APPID));
                param.Add("version", Convert.ToString(1));
                param.Add("idomain", idomain);
                param.Add("ioptype", ioptype);
                param.Add("iactionid", iactionid);
                param.Add("iworldid", iworldid);
                param.Add("vuin", vuin);
                param.Add("iuserip", iuserip);
                param.Add("ieventTime", ieventTime);
                param.Add("iroleId", iroleId);
                param.Add("ijobId", ijobId);
                param.Add("ilevel", ilevel);
                // param.Add("vparam_1", vparam_1);
                param.Add("iparam_16", iparam_16);
                param.Add("iparam_17", iparam_17);
                param.Add("iparam_18", iparam_18);
                param.Add("iparam_19", iparam_19);
                param.Add("iparam_20", iparam_20);
                param.Add("iparam_1", iparam_1);
                param.Add("vparam_4", vparam_4); //微端标识

                //
                string query_string = SnsNetWork.MakeQueryString(param);
                string script_name = "/report.php";
                //执行API 上报数据
                RstArray rs = sdk.ApiNoSig(script_name, param, false);
                if (rs.Ret != 0) //执行失败
                {
                    using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                    {
                        sqlCon.NonQueryExec("update log_report set isreport = 0 where id = '" + id.ToString() + "'");
                    }
                }
            }
        }


        #endregion

        public void SyncNoticHttpTx(GameDbInfo dbInfo)
        {
            try
            {
                using (MySQLDBConnetion sqlCon = new MySQLDBConnetion(dbInfo.DBIP, dbInfo.Account, dbInfo.PassWord, dbInfo.DBName, dbInfo.DBPort))
                {
                    string logstr = "";//dbInfo.DBName + "Db连接成功\n";
                    while (true)
                    {
                        logstr = "";
                        //logstr += "开始取" + dbInfo.DBName + "消费记录\n";
                        //                      sqlCon.NonQueryExec("update pay_token set confirm = 0");

                        DataTable dataTable = sqlCon.GetDataTable("select ts,payitem,token,billno,apiversion,zoneid,providetype,provide_errno,provide_errmsg,amt,payamt_coins,pubacct_payamt_coins,openid,openkey,pf from pay_token where roleid > 0 and confirm = 0 order by createtime asc");

                        //logstr += "本次取出记录数[" + dataTable.Rows.Count.ToString() + "] \n";
                        int row_count = dataTable.Rows.Count;
                        for (int n = 0; n < row_count; n++)
                        {
                            string ts = Convert.ToString(dataTable.Rows[n][0]);
                            string payitem = Convert.ToString(dataTable.Rows[n][1]);        // 商品ID * 商品单价 * 商品数量
                            string token_id = Convert.ToString(dataTable.Rows[n][2]);
                            string billno = Convert.ToString(dataTable.Rows[n][3]);
                            string version = Convert.ToString(dataTable.Rows[n][4]);
                            string zoneid = Convert.ToString(dataTable.Rows[n][5]);
                            string providetype = Convert.ToString(dataTable.Rows[n][6]);
                            string provide_errno = Convert.ToString(dataTable.Rows[n][7]);
                            string provide_errmsg = Convert.ToString(dataTable.Rows[n][8]);
                            string amt = Convert.ToString(dataTable.Rows[n][9]);
                            string payamt_coins = Convert.ToString(dataTable.Rows[n][10]);
                            string pubacct_payamt_coins = Convert.ToString(dataTable.Rows[n][11]);
                            // 公共参数
                            string openid = Convert.ToString(dataTable.Rows[n][12]);
                            string openkey = Convert.ToString(dataTable.Rows[n][13]);
                            string pf = Convert.ToString(dataTable.Rows[n][14]);

                            Dictionary<string, string> param = new Dictionary<string, string>();
                            param.Add("ts", ts);
                            param.Add("payitem", payitem);
                            param.Add("token_id", token_id);
                            param.Add("billno", billno);
                            param.Add("version", version);
                            param.Add("zoneid", zoneid);
                            param.Add("providetype", providetype);
                            param.Add("provide_errno", provide_errno);
                            param.Add("provide_errmsg", provide_errmsg);
                            param.Add("amt", amt);
                            param.Add("payamt_coins", payamt_coins);
                            param.Add("pubacct_payamt_coins", pubacct_payamt_coins);

                            // 加入公共参数
                            param.Add("openid", openid.ToUpper());
                            param.Add("openkey", openkey);
                            param.Add("pf", pf);
                            //fwrite.WriteLine("开始取记录22222");
                            string query_string = SnsNetWork.MakeQueryString(param);
                            // logstr += "api:[ https:///v3/pay/confirm_delivery?" + query_string + " ]  ";
                            //fwrite.WriteLine("api:[ https:///v3/pay/confirm_delivery?" + query_string + " ]");
                            string script_name = "/v3/pay/confirm_delivery ";
                            //执行API 通知QQ支付服务器 
                            RstArray rs = sdk.Api(script_name, param);
                            //logstr += "执行api结果[" + rs.Ret.ToString() + "] ";
                            // fwrite.WriteLine("执行api结果[" + rs.Ret.ToString() + "]");
                            /*
                            ret = 0: 正确返回
                            ret > 0: 调用OpenAPI时发生错误，需要开发者进行相应的处理。
                            -50 <= ret <= -1: 接口调用不能通过接口代理机校验，需要开发者进行相应的处理。
                            ret <-50: 系统内部错误，请通过企业QQ联系技术支持，调查问题原因并获得解决方案
                            //
                            1069    交易已成功结束，通知过晚（已扣款）。操作指引：交易成功，无需后续操作。 
                                
                            */
                            if (rs.Ret == 0 || rs.Ret == 1069)
                            {
                                //交易成功
                                int ret = sqlCon.NonQueryExec("update pay_token set confirm = 1, confirmret = " + rs.Ret.ToString() + " where token = '" + token_id.ToString() + "'");
                                if (ret == 1)
                                {
                                    logstr += "成功 token = '" + token_id.ToString() + "'\n";
                                }
                                else
                                {
                                    logstr += "推送成功, 但更新数据库失败 token = '" + token_id.ToString() + "'\n";
                                }
                            }
                            else
                            {
                                //发生错误
                                logstr += "失败 token = '" + token_id.ToString() + "' ErrCode: " + rs.Ret + " ErrMsg: " + rs.Msg + "\n";
                            }


                            // 成功 调用对方接口记录
                            /*
                            if ( rs.Ret == 0 ){
                                try{
                                    double db_amt = Convert.ToDouble(amt) / 10 + Convert.ToInt32(payamt_coins) + Convert.ToInt32(pubacct_payamt_coins);
                                    string openId = Common.Encode_Base64(openid);
                                    string goodsName = Common.Encode_Base64(payitem);
                                    string goodsDes = Common.Encode_Base64("xiatianxia");
                                    string secrect = Common.Encode_Base64("xtx@qgames");
                                    string orderId = Common.Encode_Base64(token_id);
                                    string areaId = Common.Encode_Base64(zoneid);
                                    string serverId = Common.Encode_Base64(zoneid);
                                    string amt_jd = Common.Encode_Base64(db_amt.ToString("#0.00"));
                                    string url = "http://p1.xtx.3977.com/no3yy_xtxyx.do?openId=" + openId + "&goodsName=" + goodsName + "&goodsDes=" + goodsDes + "&secrect=" + secrect + "&orderId=" + orderId +
                                          "&areaId=" + areaId + "&serverId=" + serverId + "&amt=" + amt_jd;
                                    //fwrite.WriteLine("[url]:" + url);
                                    logstr += "[url]:" + url + "\n";
                                    /*
                                     *  该接口返回值为(int类型)：0, 1 或 2
                                     *  如果返回值为 0 ，则表示3977支付平台充值订单数据记录失败，游戏方需把该条订单写入日志文件中，方便后续查看
                                     *  如果返回值为 1 ，则表示3977支付平台充值订单数据记录成功
                                     *  如果返回值为 2 ，则表示3977支付平台该条充值订单数据已存在
                                     * *
                                    string content = "0";
                                    for (int i = 0; i < 3; i++){
                                        HttpWebResponse Response = HttpWebResponseUtility.CreateGetHttpResponse(url, 3000, null, null);
                                        if (Response != null){
                                            StreamReader sr = new StreamReader(Response.GetResponseStream());
                                            content = sr.ReadToEnd();
                                            //fwrite.WriteLine("执行http请求结果[" + content + "]");
                                            logstr += "执行http请求结果[" + content + "]\n";
                                            if (content == "1" || content == "2"){
                                                int ret = sqlCon.NonQueryExec("update pay_token set syncret = " + content + " where token = '" + token_id.ToString() + "'");
                                                break;
                                            }
                                        }
                                    }
                                                                             
                                }
                                catch (System.Exception e){
                                        LogHelper.WriteLog("调用对方接口",  e);
                                }

                            }
                            */
                        }

                        if (row_count > 0)
                        {
                            LogHelper.WriteLog(logstr);
                        }
                        Thread.Sleep(200);
                    }
                }
            }
            catch (Exception err)
            {
                LogHelper.WriteLog(dbInfo.DBName, err);
            }
        }

        private void Exit_Click(object sender, EventArgs e)
        {
            Close();
        }

    }
}
